using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Runtime.InteropServices;
using PickGold.Charting;
using PickGold.Charting.Utilities;

namespace PickGold.Charting.ChartTypes
{
	internal class PieChart : IChartType, IDisposable
	{
		private bool _labelsFit = true;
		private bool _labelsOverlap;
		private ArrayList _labelsRectangles = new ArrayList();
		private float _sizeCorrection = 0.95f;
		private bool _sliceExploded;
		internal LabelColumn labelColumnLeft;
		internal LabelColumn labelColumnRight;

		public void AddSmartLabelMarkerPositions(CommonElements common, ChartArea area, Series series, ArrayList list)
		{
		}

		private bool ArrangeOverlappingIntervals(double[] startOfIntervals, double[] endOfIntervals, double startArea, double endArea)
		{
			if (startOfIntervals.Length != endOfIntervals.Length)
			{
				throw new InvalidOperationException(SR.ExceptionPieIntervalsInvalid);
			}
			this.ShiftOverlappingIntervals(startOfIntervals, endOfIntervals);
			double num = 0.0;
			for (int i = 0; i < (startOfIntervals.Length - 1); i++)
			{
				double num1 = endOfIntervals[i];
				double num4 = startOfIntervals[i + 1];
				num += startOfIntervals[i + 1] - endOfIntervals[i];
			}
			double num3 = (endOfIntervals[endOfIntervals.Length - 1] - endArea) + (startArea - startOfIntervals[0]);
			if (num3 <= 0.0)
			{
				this.ShiftIntervals(startOfIntervals, endOfIntervals, startArea, endArea);
				return true;
			}
			if (num3 > num)
			{
				return false;
			}
			this.ReduceEmptySpace(startOfIntervals, endOfIntervals, (num - num3) / num);
			this.ShiftIntervals(startOfIntervals, endOfIntervals, startArea, endArea);
			return true;
		}

		private void CheckPaleteColors(DataPointCollection points)
		{
			DataPoint point = points[0];
			DataPoint point2 = points[points.Count - 1];
			if ((point.tempColorIsSet && point2.tempColorIsSet) && (point.Color == point2.Color))
			{
				point2.Color = points[points.Count / 2].Color;
				point2.tempColorIsSet = true;
			}
		}

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing)
		{
		}

		private void Draw3DInsideLabels(ChartGraphics graph, PointF[] points, DataPoint point, int pointIndex)
		{
			StringFormat format = new StringFormat();
			format.LineAlignment = StringAlignment.Center;
			format.Alignment = StringAlignment.Center;
			string labelText = this.GetLabelText(point);
			PointF relativePoint = graph.GetRelativePoint(points[12]);
			SizeF relativeSize = graph.GetRelativeSize(graph.MeasureString(labelText.Replace(@"\n", "\n"), point.Font, new SizeF(1000f, 1000f), new StringFormat(StringFormat.GenericTypographic)));
			RectangleF empty = RectangleF.Empty;
			SizeF ef3 = new SizeF(relativeSize.Width, relativeSize.Height);
			ef3.Height += relativeSize.Height / 8f;
			ef3.Width += ef3.Width / ((float)labelText.Length);
			empty = new RectangleF(relativePoint.X - (ef3.Width / 2f), (relativePoint.Y - (ef3.Height / 2f)) - (relativeSize.Height / 10f), ef3.Width, ef3.Height);
			using (Brush brush = new SolidBrush(point.LabelForeColor))
			{
				graph.DrawPointLabelStringRel(graph.Common, labelText, point.Font, brush, relativePoint, format, 0, empty, point.LabelBackColor, point.LabelBorderColor, point.LabelBorderWidth, point.LabelBorderDashStyle, point.series, point, pointIndex);
			}
		}

		private void Draw3DOutsideLabels(ChartGraphics graph, ChartArea area, Pen pen, PointF[] points, DataPoint point, float midAngle, int pointIndex)
		{
			string labelText = this.GetLabelText(point);
			if (labelText.Length != 0)
			{
				graph.DrawLine(pen, points[10], points[11]);
				using (StringFormat format = new StringFormat())
				{
					LabelColumn labelColumnRight;
					PointF absolutePoint;
					format.LineAlignment = StringAlignment.Center;
					RectangleF absoluteRectangle = graph.GetAbsoluteRectangle(area.Position.ToRectangleF());
					RectangleF empty = RectangleF.Empty;
					if (((midAngle >= -90f) && (midAngle < 90f)) || ((midAngle >= 270f) && (midAngle < 450f)))
					{
						labelColumnRight = this.labelColumnRight;
						format.Alignment = StringAlignment.Near;
						float height = graph.GetAbsoluteSize(new SizeF(0f, this.labelColumnRight.columnHeight)).Height;
						absolutePoint = graph.GetAbsolutePoint(labelColumnRight.GetLabelPosition(point));
						if (points[11].X > absolutePoint.X)
						{
							absolutePoint.X = points[11].X + 10f;
						}
						empty.X = absolutePoint.X;
						empty.Width = absoluteRectangle.Right - empty.X;
						empty.Y = absolutePoint.Y - (height / 2f);
						empty.Height = height;
					}
					else
					{
						labelColumnRight = this.labelColumnLeft;
						format.Alignment = StringAlignment.Far;
						float num2 = graph.GetAbsoluteSize(new SizeF(0f, this.labelColumnLeft.columnHeight)).Height;
						absolutePoint = graph.GetAbsolutePoint(labelColumnRight.GetLabelPosition(point));
						if (points[11].X < absolutePoint.X)
						{
							absolutePoint.X = points[11].X - 10f;
						}
						empty.X = absoluteRectangle.X;
						empty.Width = absolutePoint.X - empty.X;
						empty.Y = absolutePoint.Y - (num2 / 2f);
						empty.Height = num2;
					}
					format.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap;
					format.Trimming = StringTrimming.EllipsisWord;
					graph.DrawLine(pen, points[11], absolutePoint);
					empty = graph.GetRelativeRectangle(empty);
					SizeF ef3 = graph.MeasureStringRel(labelText.Replace(@"\n", "\n"), point.Font);
					ef3.Height += ef3.Height / 8f;
					float num3 = (ef3.Width / ((float)labelText.Length)) / 2f;
					ef3.Width += num3;
					RectangleF backPosition = new RectangleF(empty.X, (empty.Y + (empty.Height / 2f)) - (ef3.Height / 2f), ef3.Width, ef3.Height);
					if (format.Alignment == StringAlignment.Near)
					{
						backPosition.X -= num3 / 2f;
					}
					else if (format.Alignment == StringAlignment.Center)
					{
						backPosition.X = empty.X + ((empty.Width - ef3.Width) / 2f);
					}
					else if (format.Alignment == StringAlignment.Far)
					{
						backPosition.X = (empty.Right - ef3.Width) - (num3 / 2f);
					}
					using (Brush brush = new SolidBrush(point.LabelForeColor))
					{
						graph.DrawPointLabelStringRel(graph.Common, labelText, point.Font, brush, empty, format, 0, backPosition, point.LabelBackColor, point.LabelBorderColor, point.LabelBorderWidth, point.LabelBorderDashStyle, point.series, point, pointIndex);
					}
				}
			}
		}

		private void Draw3DPie(int turn, ChartGraphics graph, DataPoint point, ChartArea area, RectangleF rectangle, float startAngle, float sweepAngle, float doughnutRadius, float pieWidth, bool sameBackFront, bool exploded, int pointIndex)
		{
			Pen pen2;
			SolidBrush brush = new SolidBrush(point.Color);
			Color empty = Color.Empty;
			Color color = Color.Empty;
			if ((point.BorderColor == Color.Empty) && (area.Area3DStyle.LightStyle == LightStyle.None))
			{
				empty = ChartGraphics.GetGradientColor(point.Color, Color.Black, 0.5);
			}
			else if (point.BorderColor == Color.Empty)
			{
				empty = point.Color;
			}
			else
			{
				empty = point.BorderColor;
			}
			if ((point.BorderColor != Color.Empty) || (area.Area3DStyle.LightStyle == LightStyle.None))
			{
				color = empty;
			}
			Pen pen = new Pen(empty, (float)point.BorderWidth);
			pen.DashStyle = graph.GetPenStyle(point.BorderDashStyle);
			if (point.BorderColor == Color.Empty)
			{
				pen2 = new Pen(point.Color);
			}
			else
			{
				pen2 = pen;
			}
			Pen pen3 = new Pen(color, (float)point.BorderWidth);
			pen3.DashStyle = graph.GetPenStyle(point.BorderDashStyle);
			PointF[] points = this.GetPiePoints(graph, area, pieWidth, rectangle, startAngle, sweepAngle, true, doughnutRadius, exploded);
			if (points == null)
			{
				return;
			}
			point.positionRel.X = points[10].X;
			point.positionRel.Y = points[10].Y;
			point.positionRel = graph.GetRelativePoint(point.positionRel);
			float midAngle = startAngle + (sweepAngle / 2f);
			float num2 = startAngle + sweepAngle;
			if (turn == 0)
			{
				if (!this.Doughnut)
				{
					graph.FillPieSlice(area, point, brush, pen2, points[15], points[6], points[0x10], points[7], points[9], startAngle, sweepAngle, false, pointIndex);
				}
				else
				{
					graph.FillDoughnutSlice(area, point, brush, pen2, points[15], points[6], points[0x10], points[7], points[0x18], points[0x17], startAngle, sweepAngle, false, doughnutRadius, pointIndex);
				}
			}
			else if (turn == 1)
			{
				if (sameBackFront)
				{
					if (((midAngle > -90f) && (midAngle < 90f)) || ((midAngle > 270f) && (midAngle < 450f)))
					{
						if (this.Doughnut)
						{
							this.DrawDoughnutCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, false, true, pointIndex);
						}
						this.DrawPieCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, true, true, pointIndex);
					}
					else
					{
						if (this.Doughnut)
						{
							this.DrawDoughnutCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, true, true, pointIndex);
						}
						this.DrawPieCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, false, true, pointIndex);
					}
					graph.FillPieSides(area, (float)area.Area3DStyle.Inclination, startAngle, sweepAngle, points, brush, pen, this.Doughnut);
				}
				else
				{
					if (this.Doughnut)
					{
						this.DrawDoughnutCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, false, false, pointIndex);
					}
					graph.FillPieSides(area, (float)area.Area3DStyle.Inclination, startAngle, sweepAngle, points, brush, pen, this.Doughnut);
					this.DrawPieCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, false, false, pointIndex);
				}
			}
			else if (turn == 2)
			{
				if (sameBackFront && (sweepAngle > 180f))
				{
					bool flag = (((startAngle > -180f) && (startAngle < 0f)) || ((startAngle > 180f) && (startAngle < 360f))) && (((num2 > -180f) && (num2 < 0f)) || ((num2 > 180f) && (num2 < 360f)));
					if (area.Area3DStyle.Inclination > 0)
					{
						flag = !flag;
					}
					if (((midAngle > -90f) && (midAngle < 90f)) || ((midAngle > 270f) && (midAngle < 450f)))
					{
						if ((this.Doughnut && flag) && (sweepAngle > 300f))
						{
							this.DrawDoughnutCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, true, true, pointIndex);
						}
						this.DrawPieCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, false, true, pointIndex);
					}
					else
					{
						if ((this.Doughnut && flag) && (sweepAngle > 300f))
						{
							this.DrawDoughnutCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, false, true, pointIndex);
						}
						this.DrawPieCurves(graph, area, point, startAngle, sweepAngle, points, brush, pen3, true, true, pointIndex);
					}
				}
			}
			else
			{
				if (turn == 3)
				{
					if (!this.Doughnut)
					{
						graph.FillPieSlice(area, point, brush, pen, points[13], points[4], points[14], points[5], points[8], startAngle, sweepAngle, true, pointIndex);
						graph.FillPieSlice(area, point, brush, pen, points[13], points[4], points[14], points[5], points[8], startAngle, sweepAngle, false, pointIndex);
					}
					else
					{
						graph.FillDoughnutSlice(area, point, brush, pen, points[13], points[4], points[14], points[5], points[0x16], points[0x15], startAngle, sweepAngle, true, doughnutRadius, pointIndex);
						graph.FillDoughnutSlice(area, point, brush, pen, points[13], points[4], points[14], points[5], points[0x16], points[0x15], startAngle, sweepAngle, false, doughnutRadius, pointIndex);
					}
					if (this.GetLabelStyle(point) != PieLabelStyle.Outside)
					{
						goto Label_0795;
					}
					Color color3 = pen.Color;
					if (point.IsCustomPropertySet("PieLineColor") || ((point.series != null) && point.series.IsCustomPropertySet("PieLineColor")))
					{
						ColorConverter converter = new ColorConverter();
						bool flag2 = false;
						try
						{
							if (point.IsCustomPropertySet("PieLineColor"))
							{
								color3 = (Color)converter.ConvertFromString(point["PieLineColor"]);
							}
							else if ((point.series != null) && point.series.IsCustomPropertySet("PieLineColor"))
							{
								color3 = (Color)converter.ConvertFromString(point.series["PieLineColor"]);
							}
						}
						catch (ArgumentException)
						{
							flag2 = true;
						}
						catch (NotSupportedException)
						{
							flag2 = true;
						}
						if (flag2)
						{
							if (point.IsCustomPropertySet("PieLineColor"))
							{
								color3 = (Color)converter.ConvertFromInvariantString(point["PieLineColor"]);
							}
							else if ((point.series != null) && point.series.IsCustomPropertySet("PieLineColor"))
							{
								color3 = (Color)converter.ConvertFromInvariantString(point.series["PieLineColor"]);
							}
						}
					}
					using (Pen pen4 = new Pen(color3, pen.Width))
					{
						this.Draw3DOutsideLabels(graph, area, pen4, points, point, midAngle, pointIndex);
						goto Label_0795;
					}
				}
				if (this.GetLabelStyle(point) == PieLabelStyle.Inside)
				{
					this.Draw3DInsideLabels(graph, points, point, pointIndex);
				}
			}
		Label_0795:
			if (brush != null)
			{
				brush.Dispose();
			}
			if (pen != null)
			{
				pen.Dispose();
			}
			if (pen3 != null)
			{
				pen3.Dispose();
			}
		}

		private void DrawDoughnutCurves(ChartGraphics graph, ChartArea area, DataPoint dataPoint, float startAngle, float sweepAngle, PointF[] points, SolidBrush brushWithoutLight, Pen pen, bool rightPosition, bool sameBackFront, int pointIndex)
		{
			using (new GraphicsPath())
			{
				Brush brush;
				if (area.Area3DStyle.LightStyle == LightStyle.None)
				{
					brush = brushWithoutLight;
				}
				else
				{
					brush = graph.GetGradientBrush(graph.GetAbsoluteRectangle(area.Position.ToRectangleF()), Color.FromArgb(brushWithoutLight.Color.A, 0, 0, 0), brushWithoutLight.Color, GradientStyle.VerticalCenter);
				}
				float num = startAngle + sweepAngle;
				if ((sweepAngle <= 180f) || !this.DrawDoughnutCurvesBigSlice(graph, area, dataPoint, startAngle, sweepAngle, points, brush, pen, rightPosition, sameBackFront, pointIndex))
				{
					if ((startAngle < 180f) && (num > 180f))
					{
						if (area.Area3DStyle.Inclination > 0)
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x15], points[0x11], points[0x17], points[0x12], startAngle, 180f - startAngle, pointIndex);
						}
						else
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x11], points[0x16], points[0x12], points[0x18], 180f, (startAngle + sweepAngle) - 180f, pointIndex);
						}
					}
					else if ((startAngle < 0f) && (num > 0f))
					{
						if (area.Area3DStyle.Inclination < 0)
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x15], points[0x13], points[0x17], points[20], startAngle, -startAngle, pointIndex);
						}
						else
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x13], points[0x16], points[20], points[0x18], 0f, sweepAngle + startAngle, pointIndex);
						}
					}
					else if ((startAngle < 360f) && (num > 360f))
					{
						if (area.Area3DStyle.Inclination < 0)
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x15], points[0x13], points[0x17], points[20], startAngle, 360f - startAngle, pointIndex);
						}
						else
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x13], points[0x16], points[20], points[0x18], 0f, num - 360f, pointIndex);
						}
					}
					else if (((((startAngle < 180f) && (startAngle >= 0f)) && (area.Area3DStyle.Inclination > 0)) || (((startAngle < 540f) && (startAngle >= 360f)) && (area.Area3DStyle.Inclination > 0))) || ((((startAngle >= 180f) && (startAngle < 360f)) && (area.Area3DStyle.Inclination < 0)) || (((startAngle >= -180f) && (startAngle < 0f)) && (area.Area3DStyle.Inclination < 0))))
					{
						graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x15], points[0x16], points[0x17], points[0x18], startAngle, sweepAngle, pointIndex);
					}
				}
			}
		}

		private bool DrawDoughnutCurvesBigSlice(ChartGraphics graph, ChartArea area, DataPoint dataPoint, float startAngle, float sweepAngle, PointF[] points, Brush brush, Pen pen, bool rightPosition, bool sameBackFront, int pointIndex)
		{
			float num = startAngle + sweepAngle;
			if (area.Area3DStyle.Inclination < 0)
			{
				if ((startAngle < 180f) && (num > 360f))
				{
					graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x13], points[0x11], points[20], points[0x12], 0f, -180f, pointIndex);
				}
				else
				{
					if ((startAngle >= 0f) || (num <= 180f))
					{
						return false;
					}
					if (sameBackFront)
					{
						if (rightPosition)
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x11], points[0x16], points[0x12], points[0x18], 180f, num - 180f, pointIndex);
						}
						else
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x15], points[0x13], points[0x17], points[20], startAngle, -startAngle, pointIndex);
						}
					}
					else
					{
						graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x15], points[0x13], points[0x17], points[20], startAngle, -startAngle, pointIndex);
						graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x11], points[0x16], points[0x12], points[0x18], 180f, num - 180f, pointIndex);
					}
				}
			}
			else if ((startAngle < 0f) && (num > 180f))
			{
				graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x13], points[0x11], points[20], points[0x12], 0f, 180f, pointIndex);
			}
			else
			{
				if ((startAngle >= 180f) || (num <= 360f))
				{
					return false;
				}
				if (sameBackFront)
				{
					if (rightPosition)
					{
						graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x15], points[0x11], points[0x17], points[0x12], startAngle, 180f - startAngle, pointIndex);
					}
					else
					{
						graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x13], points[0x16], points[20], points[0x18], 0f, num - 360f, pointIndex);
					}
				}
				else
				{
					graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x13], points[0x16], points[20], points[0x18], 0f, num - 360f, pointIndex);
					graph.FillPieCurve(area, dataPoint, brush, pen, points[0x19], points[0x1a], points[0x1b], points[0x1c], points[0x15], points[0x11], points[0x17], points[0x12], startAngle, 180f - startAngle, pointIndex);
				}
			}
			return true;
		}

		public void DrawLabels(ChartGraphics graph, PointF middlePoint, SizeF relativeSize, float startAngle, float sweepAngle, DataPoint point, float doughnutRadius, bool exploded, ChartArea area, bool overlapTest, int pointIndex, Color pieLineColor)
		{
			bool flag = false;
			float num3 = 1f;
			float num4 = 1f;
			Region clip = graph.Clip;
			graph.Clip = new Region();
			string labelText = this.GetLabelText(point);
			if (labelText.Length == 0)
			{
				return;
			}
			Series series = point.series;
			PieLabelStyle inside = PieLabelStyle.Inside;
			if (series.IsCustomPropertySet("LabelStyle"))
			{
				string strA = series["LabelStyle"];
				if (string.Compare(strA, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(strA, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			else if (series.IsCustomPropertySet("PieLabelStyle"))
			{
				string str3 = series["PieLabelStyle"];
				if (string.Compare(str3, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(str3, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			if (point.IsCustomPropertySet("LabelStyle"))
			{
				string str4 = point["LabelStyle"];
				if (string.Compare(str4, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(str4, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			else if (point.IsCustomPropertySet("PieLabelStyle"))
			{
				string str5 = point["PieLabelStyle"];
				if (string.Compare(str5, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(str5, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			if (series.IsCustomPropertySet("LabelsRadialLineSize"))
			{
				string stringToParse = series["LabelsRadialLineSize"];
				num4 = CommonElements.ParseFloat(stringToParse);
				if ((num4 < 0f) || (num4 > 100f))
				{
					throw new InvalidOperationException(SR.ExceptionPieRadialLineSizeInvalid);
				}
			}
			if (point.IsCustomPropertySet("LabelsRadialLineSize"))
			{
				string str7 = point["LabelsRadialLineSize"];
				num4 = CommonElements.ParseFloat(str7);
				if ((num4 < 0f) || (num4 > 100f))
				{
					throw new InvalidOperationException(SR.ExceptionPieRadialLineSizeInvalid);
				}
			}
			if (series.IsCustomPropertySet("LabelsHorizontalLineSize"))
			{
				string str8 = series["LabelsHorizontalLineSize"];
				num3 = CommonElements.ParseFloat(str8);
				if ((num3 < 0f) || (num3 > 100f))
				{
					throw new InvalidOperationException(SR.ExceptionPieHorizontalLineSizeInvalid);
				}
			}
			if (point.IsCustomPropertySet("LabelsHorizontalLineSize"))
			{
				string str9 = point["LabelsHorizontalLineSize"];
				num3 = CommonElements.ParseFloat(str9);
				if ((num3 < 0f) || (num3 > 100f))
				{
					throw new InvalidOperationException(SR.ExceptionPieHorizontalLineSizeInvalid);
				}
			}
			float num6 = 1f;
			if ((inside == PieLabelStyle.Inside) && !overlapTest)
			{
				float num7;
				float num8;
				if (exploded)
				{
					num6 = 1.4f;
				}
				float result = 4f;
				if (point.IsCustomPropertySet("InsideLabelOffset"))
				{
					if ((!float.TryParse(point["InsideLabelOffset"], NumberStyles.Any, CultureInfo.InvariantCulture, out result) || (result < 0f)) || (result > 100f))
					{
						throw new InvalidOperationException(SR.ExceptionCustomAttributeIsNotInRange0to100("InsideLabelOffset"));
					}
					result = 4f / (1f + (result / 100f));
				}
				if (this.Doughnut)
				{
					num7 = ((relativeSize.Width * num6) / result) * (1f + ((100f - doughnutRadius) / 100f));
					num8 = ((relativeSize.Height * num6) / result) * (1f + ((100f - doughnutRadius) / 100f));
				}
				else
				{
					num7 = (relativeSize.Width * num6) / result;
					num8 = (relativeSize.Height * num6) / result;
				}
				float x = (((float)Math.Cos(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * num7) + middlePoint.X;
				float y = (((float)Math.Sin(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * num8) + middlePoint.Y;
				using (StringFormat format = new StringFormat())
				{
					format.Alignment = StringAlignment.Center;
					format.LineAlignment = StringAlignment.Center;
					SizeF ef = graph.GetRelativeSize(graph.MeasureString(labelText.Replace(@"\n", "\n"), point.Font, new SizeF(1000f, 1000f), StringFormat.GenericTypographic));
					RectangleF empty = RectangleF.Empty;
					SizeF size = new SizeF(ef.Width, ef.Height);
					size.Height += size.Height / 8f;
					size.Width += size.Width / ((float)labelText.Length);
					empty = PointChart.GetLabelPosition(graph, new PointF(x, y), size, format, true);
					using (Brush brush = new SolidBrush(point.LabelForeColor))
					{
						graph.DrawPointLabelStringRel(area.Common, labelText, point.Font, brush, new PointF(x, y), format, point.LabelAngle, empty, point.LabelBackColor, point.LabelBorderColor, point.LabelBorderWidth, point.LabelBorderDashStyle, series, point, pointIndex);
					}
					goto Label_0A9D;
				}
			}
			if (inside == PieLabelStyle.Outside)
			{
				float num5 = 0.5f + (num4 * 0.1f);
				if (exploded)
				{
					num6 = 1.2f;
				}
				float num10 = startAngle + (sweepAngle / 2f);
				float num11 = (((((float)Math.Cos((num10 * 3.1415926535897931) / 180.0)) * relativeSize.Width) * num6) / 2f) + middlePoint.X;
				float num12 = (((((float)Math.Sin((num10 * 3.1415926535897931) / 180.0)) * relativeSize.Height) * num6) / 2f) + middlePoint.Y;
				float num13 = (((((float)Math.Cos((num10 * 3.1415926535897931) / 180.0)) * relativeSize.Width) * num5) * num6) + middlePoint.X;
				float num14 = (((((float)Math.Sin((num10 * 3.1415926535897931) / 180.0)) * relativeSize.Height) * num5) * num6) + middlePoint.Y;
				if (pieLineColor == Color.Empty)
				{
					pieLineColor = point.BorderColor;
				}
				if (!overlapTest)
				{
					graph.DrawLineRel(pieLineColor, point.BorderWidth, ChartDashStyle.Solid, new PointF(num11, num12), new PointF(num13, num14));
				}
				using (StringFormat format2 = new StringFormat())
				{
					float num16;
					float num17;
					format2.Alignment = StringAlignment.Center;
					format2.LineAlignment = StringAlignment.Center;
					float num15 = (((((float)Math.Sin((num10 * 3.1415926535897931) / 180.0)) * relativeSize.Height) * num5) * num6) + middlePoint.Y;
					RectangleF ef4 = RectangleF.Empty;
					RectangleF labelRect = RectangleF.Empty;
					if ((num10 > 90f) && (num10 < 270f))
					{
						format2.Alignment = StringAlignment.Far;
						num17 = (((-relativeSize.Width * num5) * num6) + middlePoint.X) - ((relativeSize.Width / 10f) * num3);
						num16 = ((((((float)Math.Cos((num10 * 3.1415926535897931) / 180.0)) * relativeSize.Width) * num5) * num6) + middlePoint.X) - ((relativeSize.Width / 10f) * num3);
						if (overlapTest)
						{
							num17 = num16;
						}
						ef4 = this.GetLabelRect(new PointF(num16, num15), area, labelText, format2, graph, point, true);
						labelRect = this.GetLabelRect(new PointF(num17, num15), area, labelText, format2, graph, point, true);
					}
					else
					{
						format2.Alignment = StringAlignment.Near;
						num17 = (((relativeSize.Width * num5) * num6) + middlePoint.X) + ((relativeSize.Width / 10f) * num3);
						num16 = ((((((float)Math.Cos((num10 * 3.1415926535897931) / 180.0)) * relativeSize.Width) * num5) * num6) + middlePoint.X) + ((relativeSize.Width / 10f) * num3);
						if (overlapTest)
						{
							num17 = num16;
						}
						ef4 = this.GetLabelRect(new PointF(num16, num15), area, labelText, format2, graph, point, false);
						labelRect = this.GetLabelRect(new PointF(num17, num15), area, labelText, format2, graph, point, false);
					}
					if (!overlapTest)
					{
						if (this._labelsOverlap)
						{
							RectangleF ef9 = (RectangleF)this._labelsRectangles[pointIndex];
							RectangleF ef10 = (RectangleF)this._labelsRectangles[pointIndex];
							float num18 = (ef9.Top + ef10.Bottom) / 2f;
							graph.DrawLineRel(pieLineColor, point.BorderWidth, ChartDashStyle.Solid, new PointF(num13, num14), new PointF(num17, num18));
						}
						else
						{
							graph.DrawLineRel(pieLineColor, point.BorderWidth, ChartDashStyle.Solid, new PointF(num13, num14), new PointF(num16, num15));
						}
					}
					if (!overlapTest)
					{
						RectangleF position = new RectangleF(ef4.Location, ef4.Size);
						if (this._labelsOverlap)
						{
							position = (RectangleF)this._labelsRectangles[pointIndex];
							position.X = labelRect.X;
							position.Width = labelRect.Width;
						}
						SizeF ef7 = graph.MeasureStringRel(labelText.Replace(@"\n", "\n"), point.Font);
						ef7.Height += ef7.Height / 8f;
						float num19 = (ef7.Width / ((float)labelText.Length)) / 2f;
						ef7.Width += num19;
						RectangleF backPosition = new RectangleF(position.X, (position.Y + (position.Height / 2f)) - (ef7.Height / 2f), ef7.Width, ef7.Height);
						if (format2.Alignment == StringAlignment.Near)
						{
							backPosition.X -= num19 / 2f;
						}
						else if (format2.Alignment == StringAlignment.Center)
						{
							backPosition.X = position.X + ((position.Width - ef7.Width) / 2f);
						}
						else if (format2.Alignment == StringAlignment.Far)
						{
							backPosition.X = (position.Right - ef7.Width) - (num19 / 2f);
						}
						using (Brush brush2 = new SolidBrush(point.LabelForeColor))
						{
							graph.DrawPointLabelStringRel(area.Common, labelText, point.Font, brush2, position, format2, point.LabelAngle, backPosition, point.LabelBackColor, point.LabelBorderColor, point.LabelBorderWidth, point.LabelBorderDashStyle, series, point, pointIndex);
							goto Label_0A9D;
						}
					}
					this.InsertOverlapLabel(labelRect);
					flag = true;
				}
			}
		Label_0A9D:
			graph.Clip = clip;
			if (!flag)
			{
				this.InsertOverlapLabel(RectangleF.Empty);
			}
		}

		private void DrawPieCurves(ChartGraphics graph, ChartArea area, DataPoint dataPoint, float startAngle, float sweepAngle, PointF[] points, SolidBrush brushWithoutLight, Pen pen, bool rightPosition, bool sameBackFront, int pointIndex)
		{
			using (new GraphicsPath())
			{
				Brush brush;
				if (area.Area3DStyle.LightStyle == LightStyle.None)
				{
					brush = brushWithoutLight;
				}
				else
				{
					brush = graph.GetGradientBrush(graph.GetAbsoluteRectangle(area.Position.ToRectangleF()), Color.FromArgb(brushWithoutLight.Color.A, 0, 0, 0), brushWithoutLight.Color, GradientStyle.VerticalCenter);
				}
				float num = startAngle + sweepAngle;
				if ((sweepAngle <= 180f) || !this.DrawPieCurvesBigSlice(graph, area, dataPoint, startAngle, sweepAngle, points, brush, pen, rightPosition, sameBackFront, pointIndex))
				{
					if ((startAngle < 180f) && (num > 180f))
					{
						if (area.Area3DStyle.Inclination < 0)
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[4], points[0], points[6], points[1], startAngle, 180f - startAngle, pointIndex);
						}
						else
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[0], points[5], points[1], points[7], 180f, (startAngle + sweepAngle) - 180f, pointIndex);
						}
					}
					else if ((startAngle < 0f) && (num > 0f))
					{
						if (area.Area3DStyle.Inclination > 0)
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[4], points[2], points[6], points[3], startAngle, -startAngle, pointIndex);
						}
						else
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[2], points[5], points[3], points[7], 0f, sweepAngle + startAngle, pointIndex);
						}
					}
					else if ((startAngle < 360f) && (num > 360f))
					{
						if (area.Area3DStyle.Inclination > 0)
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[4], points[2], points[6], points[3], startAngle, 360f - startAngle, pointIndex);
						}
						else
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[2], points[5], points[3], points[7], 0f, num - 360f, pointIndex);
						}
					}
					else if (((((startAngle < 180f) && (startAngle >= 0f)) && (area.Area3DStyle.Inclination < 0)) || (((startAngle < 540f) && (startAngle >= 360f)) && (area.Area3DStyle.Inclination < 0))) || ((((startAngle >= 180f) && (startAngle < 360f)) && (area.Area3DStyle.Inclination > 0)) || (((startAngle >= -180f) && (startAngle < 0f)) && (area.Area3DStyle.Inclination > 0))))
					{
						graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[4], points[5], points[6], points[7], startAngle, sweepAngle, pointIndex);
					}
				}
			}
		}

		private bool DrawPieCurvesBigSlice(ChartGraphics graph, ChartArea area, DataPoint dataPoint, float startAngle, float sweepAngle, PointF[] points, Brush brush, Pen pen, bool rightPosition, bool sameBackFront, int pointIndex)
		{
			float num = startAngle + sweepAngle;
			if (area.Area3DStyle.Inclination > 0)
			{
				if ((startAngle < 180f) && (num > 360f))
				{
					graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[2], points[0], points[3], points[1], 0f, -180f, pointIndex);
				}
				else
				{
					if ((startAngle >= 0f) || (num <= 180f))
					{
						return false;
					}
					if (sameBackFront)
					{
						if (rightPosition)
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[0], points[5], points[1], points[7], 180f, num - 180f, pointIndex);
						}
						else
						{
							graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[4], points[2], points[6], points[3], startAngle, -startAngle, pointIndex);
						}
					}
					else
					{
						graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[4], points[2], points[6], points[3], startAngle, -startAngle, pointIndex);
						graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[0], points[5], points[1], points[7], 180f, num - 180f, pointIndex);
					}
				}
			}
			else if ((startAngle < 0f) && (num > 180f))
			{
				graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[2], points[0], points[3], points[1], 0f, 180f, pointIndex);
			}
			else
			{
				if ((startAngle >= 180f) || (num <= 360f))
				{
					return false;
				}
				if (sameBackFront)
				{
					if (rightPosition)
					{
						graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[4], points[0], points[6], points[1], startAngle, 180f - startAngle, pointIndex);
					}
					else
					{
						graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[2], points[5], points[3], points[7], 0f, num - 360f, pointIndex);
					}
				}
				else
				{
					graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[2], points[5], points[3], points[7], 0f, num - 360f, pointIndex);
					graph.FillPieCurve(area, dataPoint, brush, pen, points[13], points[14], points[15], points[0x10], points[4], points[0], points[6], points[1], startAngle, 180f - startAngle, pointIndex);
				}
			}
			return true;
		}

		public bool EstimateLabels(ChartGraphics graph, PointF middlePoint, SizeF relativeSize, float startAngle, float sweepAngle, DataPoint point, bool exploded, ChartArea area)
		{
			float num = 1f;
			float num2 = 1f;
			string pointLabel = this.GetPointLabel(point);
			Series series = point.series;
			PieLabelStyle inside = PieLabelStyle.Inside;
			if (series.IsCustomPropertySet("LabelStyle"))
			{
				string strA = series["LabelStyle"];
				if (string.Compare(strA, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(strA, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			else if (series.IsCustomPropertySet("PieLabelStyle"))
			{
				string str3 = series["PieLabelStyle"];
				if (string.Compare(str3, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(str3, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			if (point.IsCustomPropertySet("LabelStyle"))
			{
				string str4 = point["LabelStyle"];
				if (string.Compare(str4, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(str4, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			else if (point.IsCustomPropertySet("PieLabelStyle"))
			{
				string str5 = point["PieLabelStyle"];
				if (string.Compare(str5, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(str5, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			if (series.IsCustomPropertySet("LabelsRadialLineSize"))
			{
				string stringToParse = series["LabelsRadialLineSize"];
				num2 = CommonElements.ParseFloat(stringToParse);
				if ((num2 < 0f) || (num2 > 100f))
				{
					throw new InvalidOperationException(SR.ExceptionPieRadialLineSizeInvalid);
				}
			}
			if (point.IsCustomPropertySet("LabelsRadialLineSize"))
			{
				string str7 = point["LabelsRadialLineSize"];
				num2 = CommonElements.ParseFloat(str7);
				if ((num2 < 0f) || (num2 > 100f))
				{
					throw new InvalidOperationException(SR.ExceptionPieRadialLineSizeInvalid);
				}
			}
			if (series.IsCustomPropertySet("LabelsHorizontalLineSize"))
			{
				string str8 = series["LabelsHorizontalLineSize"];
				num = CommonElements.ParseFloat(str8);
				if ((num < 0f) || (num > 100f))
				{
					throw new InvalidOperationException(SR.ExceptionPieHorizontalLineSizeInvalid);
				}
			}
			if (point.IsCustomPropertySet("LabelsHorizontalLineSize"))
			{
				string str9 = point["LabelsHorizontalLineSize"];
				num = CommonElements.ParseFloat(str9);
				if ((num < 0f) || (num > 100f))
				{
					throw new InvalidOperationException(SR.ExceptionPieHorizontalLineSizeInvalid);
				}
			}
			float num4 = 1f;
			if (inside == PieLabelStyle.Outside)
			{
				float num7;
				string str10;
				float num3 = 0.5f + (num2 * 0.1f);
				if (exploded)
				{
					num4 = 1.2f;
				}
				float num5 = startAngle + (sweepAngle / 2f);
				float num6 = (((((float)Math.Sin((num5 * 3.1415926535897931) / 180.0)) * relativeSize.Height) * num3) * num4) + middlePoint.Y;
				if ((num5 > 90f) && (num5 < 270f))
				{
					num7 = ((((((float)Math.Cos((num5 * 3.1415926535897931) / 180.0)) * relativeSize.Width) * num3) * num4) + middlePoint.X) - ((relativeSize.Width / 10f) * num);
				}
				else
				{
					num7 = ((((((float)Math.Cos((num5 * 3.1415926535897931) / 180.0)) * relativeSize.Width) * num3) * num4) + middlePoint.X) + ((relativeSize.Width / 10f) * num);
				}
				if ((pointLabel.Length == 0) && point.IsValueShownAsLabel)
				{
					str10 = ValueConverter.FormatValue(series.Chart, point, point.Tag, point.YValues[0], point.LabelFormat, point.series.YValueType, ChartElementType.DataPoint);
				}
				else
				{
					str10 = pointLabel;
				}
				SizeF ef = graph.MeasureStringRel(str10.Replace(@"\n", "\n"), point.Font);
				this._labelsFit = true;
				if (this._labelsOverlap)
				{
					if ((num5 > 90f) && (num5 < 270f))
					{
						float num8 = (((-relativeSize.Width * num3) * num4) + middlePoint.X) - ((relativeSize.Width / 10f) * num);
						if ((num8 - ef.Width) < area.Position.X)
						{
							this._labelsFit = false;
						}
					}
					else
					{
						float num9 = (((relativeSize.Width * num3) * num4) + middlePoint.X) + ((relativeSize.Width / 10f) * num);
						if ((num9 + ef.Width) > area.Position.Right)
						{
							this._labelsFit = false;
						}
					}
				}
				else
				{
					if ((num5 > 90f) && (num5 < 270f))
					{
						if ((num7 - ef.Width) < area.PlotAreaPosition.ToRectangleF().Left)
						{
							this._labelsFit = false;
						}
					}
					else if ((num7 + ef.Width) > area.PlotAreaPosition.ToRectangleF().Right)
					{
						this._labelsFit = false;
					}
					if ((num5 > 180f) && (num5 < 360f))
					{
						if ((num6 - (ef.Height / 2f)) < area.PlotAreaPosition.ToRectangleF().Top)
						{
							this._labelsFit = false;
						}
					}
					else if ((num6 + (ef.Height / 2f)) > area.PlotAreaPosition.ToRectangleF().Bottom)
					{
						this._labelsFit = false;
					}
				}
			}
			return true;
		}

		private void FillPieLabelOutside(ChartGraphics graph, ChartArea area, RectangleF pieRectangle, float pieWidth, DataPoint point, float startAngle, float sweepAngle, int pointIndx, float doughnutRadius, bool exploded)
		{
			float num = startAngle + (sweepAngle / 2f);
			float y = this.GetPiePoints(graph, area, pieWidth, pieRectangle, startAngle, sweepAngle, false, doughnutRadius, exploded)[11].Y;
			if (((num >= -90f) && (num < 90f)) || ((num >= 270f) && (num < 450f)))
			{
				this.labelColumnRight.InsertLabel(point, y, pointIndx);
			}
			else
			{
				this.labelColumnLeft.InsertLabel(point, y, pointIndx);
			}
		}

		public virtual Image GetImage(ChartTypeRegistry registry)
		{
			return (Image)registry.ResourceManager.GetObject(this.Name + "ChartType");
		}

		private RectangleF GetLabelRect(PointF labelPosition, ChartArea area, string text, StringFormat format, ChartGraphics graph, DataPoint point, bool leftOrientation)
		{
			RectangleF empty = RectangleF.Empty;
			if (leftOrientation)
			{
				empty.X = area.Position.X;
				empty.Y = area.Position.Y;
				empty.Width = labelPosition.X - area.Position.X;
				empty.Height = area.Position.Height;
			}
			else
			{
				empty.X = labelPosition.X;
				empty.Y = area.Position.Y;
				empty.Width = area.Position.Right - labelPosition.X;
				empty.Height = area.Position.Height;
			}
			SizeF ef2 = graph.MeasureStringRel(text.Replace(@"\n", "\n"), point.Font, empty.Size, format);
			empty.Y = labelPosition.Y - ((ef2.Height / 2f) * 1.8f);
			empty.Height = ef2.Height * 1.8f;
			return empty;
		}

		private PieLabelStyle GetLabelStyle(DataPoint point)
		{
			Series series = point.series;
			PieLabelStyle inside = PieLabelStyle.Inside;
			if (series.IsCustomPropertySet("LabelStyle"))
			{
				string str = series["LabelStyle"];
				if (string.Compare(str, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(str, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			else if (series.IsCustomPropertySet("PieLabelStyle"))
			{
				string str2 = series["PieLabelStyle"];
				if (string.Compare(str2, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Disabled;
				}
				else if (string.Compare(str2, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					inside = PieLabelStyle.Outside;
				}
				else
				{
					inside = PieLabelStyle.Inside;
				}
			}
			if (point.IsCustomPropertySet("LabelStyle"))
			{
				string str3 = point["LabelStyle"];
				if (string.Compare(str3, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
				{
					return PieLabelStyle.Disabled;
				}
				if (string.Compare(str3, "outside", StringComparison.OrdinalIgnoreCase) == 0)
				{
					return PieLabelStyle.Outside;
				}
				return PieLabelStyle.Inside;
			}
			if (!point.IsCustomPropertySet("PieLabelStyle"))
			{
				return inside;
			}
			string strA = point["PieLabelStyle"];
			if (string.Compare(strA, "disabled", StringComparison.OrdinalIgnoreCase) == 0)
			{
				return PieLabelStyle.Disabled;
			}
			if (string.Compare(strA, "outside", StringComparison.OrdinalIgnoreCase) == 0)
			{
				return PieLabelStyle.Outside;
			}
			return PieLabelStyle.Inside;
		}

		private string GetLabelText(DataPoint point)
		{
			string pointLabel = this.GetPointLabel(point);
			if ((point.Label.Length == 0) && point.IsValueShownAsLabel)
			{
				return ValueConverter.FormatValue(point.series.Chart, point, point.Tag, point.YValues[0], point.LabelFormat, point.series.YValueType, ChartElementType.DataPoint);
			}
			return pointLabel;
		}

		public virtual LegendImageStyle GetLegendImageStyle(Series series)
		{
			return LegendImageStyle.Rectangle;
		}

		private PointF[] GetPiePoints(ChartGraphics graph, ChartArea area, float pieWidth, RectangleF rectangle, float startAngle, float sweepAngle, bool relativeCoordinates, float doughnutRadius, bool exploded)
		{
			Point3D[] pointdArray;
			PointF[] tfArray;
			float num;
			doughnutRadius = 1f - (doughnutRadius / 100f);
			if (this.Doughnut)
			{
				pointdArray = new Point3D[0x1d];
				tfArray = new PointF[0x1d];
			}
			else
			{
				pointdArray = new Point3D[0x11];
				tfArray = new PointF[0x11];
			}
			pointdArray[0] = new Point3D((rectangle.X + ((((float)Math.Cos(3.1415926535897931)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin(3.1415926535897931)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), pieWidth);
			pointdArray[1] = new Point3D((rectangle.X + ((((float)Math.Cos(3.1415926535897931)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin(3.1415926535897931)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), 0f);
			pointdArray[2] = new Point3D((rectangle.X + ((((float)Math.Cos(0.0)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin(0.0)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), pieWidth);
			pointdArray[3] = new Point3D((rectangle.X + ((((float)Math.Cos(0.0)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin(0.0)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), 0f);
			pointdArray[4] = new Point3D((rectangle.X + ((((float)Math.Cos((startAngle * 3.1415926535897931) / 180.0)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin((startAngle * 3.1415926535897931) / 180.0)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), pieWidth);
			pointdArray[5] = new Point3D((rectangle.X + ((((float)Math.Cos(((startAngle + sweepAngle) * 3.1415926535897931) / 180.0)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin(((startAngle + sweepAngle) * 3.1415926535897931) / 180.0)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), pieWidth);
			pointdArray[6] = new Point3D((rectangle.X + ((((float)Math.Cos((startAngle * 3.1415926535897931) / 180.0)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin((startAngle * 3.1415926535897931) / 180.0)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), 0f);
			pointdArray[7] = new Point3D((rectangle.X + ((((float)Math.Cos(((startAngle + sweepAngle) * 3.1415926535897931) / 180.0)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin(((startAngle + sweepAngle) * 3.1415926535897931) / 180.0)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), 0f);
			pointdArray[8] = new Point3D(rectangle.X + (rectangle.Width / 2f), rectangle.Y + (rectangle.Height / 2f), pieWidth);
			pointdArray[9] = new Point3D(rectangle.X + (rectangle.Width / 2f), rectangle.Y + (rectangle.Height / 2f), 0f);
			pointdArray[10] = new Point3D((rectangle.X + ((((float)Math.Cos(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * rectangle.Width) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + ((((float)Math.Sin(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * rectangle.Height) / 2f)) + (rectangle.Height / 2f), pieWidth);
			if (exploded)
			{
				num = 1.1f;
			}
			else
			{
				num = 1.3f;
			}
			pointdArray[11] = new Point3D((rectangle.X + (((((float)Math.Cos(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * rectangle.Width) * num) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * rectangle.Height) * num) / 2f)) + (rectangle.Height / 2f), pieWidth);
			if (this.Doughnut)
			{
				pointdArray[12] = new Point3D((rectangle.X + (((((float)Math.Cos(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * rectangle.Width) * (1f + doughnutRadius)) / 4f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * rectangle.Height) * (1f + doughnutRadius)) / 4f)) + (rectangle.Height / 2f), pieWidth);
			}
			else
			{
				pointdArray[12] = new Point3D((rectangle.X + (((((float)Math.Cos(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * rectangle.Width) * 0.5f) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(((startAngle + (sweepAngle / 2f)) * 3.1415926535897931) / 180.0)) * rectangle.Height) * 0.5f) / 2f)) + (rectangle.Height / 2f), pieWidth);
			}
			pointdArray[13] = new Point3D(rectangle.X, rectangle.Y, pieWidth);
			pointdArray[14] = new Point3D(rectangle.Right, rectangle.Bottom, pieWidth);
			pointdArray[15] = new Point3D(rectangle.X, rectangle.Y, 0f);
			pointdArray[0x10] = new Point3D(rectangle.Right, rectangle.Bottom, 0f);
			if (this.Doughnut)
			{
				pointdArray[0x11] = new Point3D((rectangle.X + (((((float)Math.Cos(3.1415926535897931)) * rectangle.Width) * doughnutRadius) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(3.1415926535897931)) * rectangle.Height) * doughnutRadius) / 2f)) + (rectangle.Height / 2f), pieWidth);
				pointdArray[0x12] = new Point3D((rectangle.X + (((((float)Math.Cos(3.1415926535897931)) * rectangle.Width) * doughnutRadius) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(3.1415926535897931)) * rectangle.Height) * doughnutRadius) / 2f)) + (rectangle.Height / 2f), 0f);
				pointdArray[0x13] = new Point3D((rectangle.X + (((((float)Math.Cos(0.0)) * rectangle.Width) * doughnutRadius) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(0.0)) * rectangle.Height) * doughnutRadius) / 2f)) + (rectangle.Height / 2f), pieWidth);
				pointdArray[20] = new Point3D((rectangle.X + (((((float)Math.Cos(0.0)) * rectangle.Width) * doughnutRadius) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(0.0)) * rectangle.Height) * doughnutRadius) / 2f)) + (rectangle.Height / 2f), 0f);
				pointdArray[0x15] = new Point3D((rectangle.X + (((((float)Math.Cos((startAngle * 3.1415926535897931) / 180.0)) * rectangle.Width) * doughnutRadius) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin((startAngle * 3.1415926535897931) / 180.0)) * rectangle.Height) * doughnutRadius) / 2f)) + (rectangle.Height / 2f), pieWidth);
				pointdArray[0x16] = new Point3D((rectangle.X + (((((float)Math.Cos(((startAngle + sweepAngle) * 3.1415926535897931) / 180.0)) * rectangle.Width) * doughnutRadius) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(((startAngle + sweepAngle) * 3.1415926535897931) / 180.0)) * rectangle.Height) * doughnutRadius) / 2f)) + (rectangle.Height / 2f), pieWidth);
				pointdArray[0x17] = new Point3D((rectangle.X + (((((float)Math.Cos((startAngle * 3.1415926535897931) / 180.0)) * rectangle.Width) * doughnutRadius) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin((startAngle * 3.1415926535897931) / 180.0)) * rectangle.Height) * doughnutRadius) / 2f)) + (rectangle.Height / 2f), 0f);
				pointdArray[0x18] = new Point3D((rectangle.X + (((((float)Math.Cos(((startAngle + sweepAngle) * 3.1415926535897931) / 180.0)) * rectangle.Width) * doughnutRadius) / 2f)) + (rectangle.Width / 2f), (rectangle.Y + (((((float)Math.Sin(((startAngle + sweepAngle) * 3.1415926535897931) / 180.0)) * rectangle.Height) * doughnutRadius) / 2f)) + (rectangle.Height / 2f), 0f);
				rectangle.Inflate((-rectangle.Width * (1f - doughnutRadius)) / 2f, (-rectangle.Height * (1f - doughnutRadius)) / 2f);
				pointdArray[0x19] = new Point3D(rectangle.X, rectangle.Y, pieWidth);
				pointdArray[0x1a] = new Point3D(rectangle.Right, rectangle.Bottom, pieWidth);
				pointdArray[0x1b] = new Point3D(rectangle.X, rectangle.Y, 0f);
				pointdArray[0x1c] = new Point3D(rectangle.Right, rectangle.Bottom, 0f);
			}
			area.matrix3D.TransformPoints(pointdArray);
			int index = 0;
			foreach (Point3D pointd in pointdArray)
			{
				tfArray[index] = pointd.PointF;
				if (relativeCoordinates)
				{
					tfArray[index] = graph.GetAbsolutePoint(tfArray[index]);
				}
				index++;
			}
			return tfArray;
		}

		private string GetPointLabel(DataPoint point)
		{
			string strOriginal = string.Empty;
			if (point.Label.Length == 0)
			{
				strOriginal = point.AxisLabel;
				if (((point.series != null) && point.series.IsCustomPropertySet("AutoAxisLabels")) && string.Equals(point.series.GetCustomProperty("AutoAxisLabels"), "false", StringComparison.OrdinalIgnoreCase))
				{
					strOriginal = string.Empty;
				}
			}
			else
			{
				strOriginal = point.Label;
			}
			return point.ReplaceKeywords(strOriginal);
		}

		public virtual double GetYValue(CommonElements common, ChartArea area, Series series, DataPoint point, int pointIndex, int yValueIndex)
		{
			return point.YValues[yValueIndex];
		}

		private void InitPieSize(ChartGraphics graph, ChartArea area, ref RectangleF pieRectangle, ref float pieWidth, DataPoint[] dataPoints, float[] startAngleList, float[] sweepAngleList, Series series, float labelLineSize)
		{
			this.labelColumnLeft = new LabelColumn(area.Position.ToRectangleF());
			this.labelColumnRight = new LabelColumn(area.Position.ToRectangleF());
			float minValue = float.MinValue;
			float num2 = float.MinValue;
			int index = 0;
			foreach (DataPoint point in dataPoints)
			{
				if (!point.IsEmpty)
				{
					float num4 = startAngleList[index] + (sweepAngleList[index] / 2f);
					if (((num4 >= -90f) && (num4 < 90f)) || ((num4 >= 270f) && (num4 < 450f)))
					{
						this.labelColumnRight.numOfItems++;
					}
					else
					{
						this.labelColumnLeft.numOfItems++;
					}
					SizeF ef = graph.MeasureStringRel(this.GetLabelText(point).Replace(@"\n", "\n"), point.Font);
					minValue = Math.Max(ef.Width, minValue);
					num2 = Math.Max(ef.Height, num2);
					index++;
				}
			}
			float width = pieRectangle.Width;
			float height = pieRectangle.Height;
			pieRectangle.Width = (pieRectangle.Width - (2f * minValue)) - ((2f * pieRectangle.Width) * labelLineSize);
			pieRectangle.Height -= pieRectangle.Height * 0.3f;
			if (pieRectangle.Width < (width * ((float)this.MinimumRelativePieSize(area))))
			{
				pieRectangle.Width = width * ((float)this.MinimumRelativePieSize(area));
			}
			if (pieRectangle.Height < (height * ((float)this.MinimumRelativePieSize(area))))
			{
				pieRectangle.Height = height * ((float)this.MinimumRelativePieSize(area));
			}
			if ((width * 0.8f) < pieRectangle.Width)
			{
				pieRectangle.Width *= 0.8f;
			}
			pieRectangle.X += (width - pieRectangle.Width) / 2f;
			pieWidth = (pieRectangle.Width / width) * pieWidth;
			pieRectangle.Y += (height - pieRectangle.Height) / 2f;
			SizeF size = new SizeF(1.4f * series.Font.Size, 1.4f * series.Font.Size);
			size = graph.GetRelativeSize(size);
			int maxNumOfRows = (int)(pieRectangle.Height / num2);
			this.labelColumnRight.Initialize(pieRectangle, true, maxNumOfRows, labelLineSize);
			this.labelColumnLeft.Initialize(pieRectangle, false, maxNumOfRows, labelLineSize);
		}

		private void InsertOverlapLabel(RectangleF labelRect)
		{
			if (!labelRect.IsEmpty)
			{
				foreach (RectangleF ef in this._labelsRectangles)
				{
					if (labelRect.IntersectsWith(ef))
					{
						this._labelsOverlap = true;
					}
				}
			}
			this._labelsRectangles.Add(labelRect);
		}

		private void Map(CommonElements common, DataPoint point, float startAngle, float sweepAngle, RectangleF rectangle, bool doughnut, float doughnutRadius, ChartGraphics graph, int pointIndex)
		{
			using (GraphicsPath path = new GraphicsPath())
			{
				RectangleF empty = RectangleF.Empty;
				empty.X = rectangle.X + ((rectangle.Width * (1f - ((100f - doughnutRadius) / 100f))) / 2f);
				empty.Y = rectangle.Y + ((rectangle.Height * (1f - ((100f - doughnutRadius) / 100f))) / 2f);
				empty.Width = (rectangle.Width * (100f - doughnutRadius)) / 100f;
				empty.Height = (rectangle.Height * (100f - doughnutRadius)) / 100f;
				rectangle = graph.GetAbsoluteRectangle(rectangle);
				path.AddPie(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, startAngle, sweepAngle);
				if (doughnut)
				{
					empty = graph.GetAbsoluteRectangle(empty);
					path.AddPie(empty.X, empty.Y, empty.Width, empty.Width, startAngle, sweepAngle);
				}
				path.Flatten(new Matrix(), 1f);
				PointF[] tfArray = new PointF[path.PointCount];
				for (int i = 0; i < path.PointCount; i++)
				{
					tfArray[i] = graph.GetRelativePoint(path.PathPoints[i]);
				}
				float[] coord = new float[path.PointCount * 2];
				for (int j = 0; j < path.PointCount; j++)
				{
					coord[2 * j] = tfArray[j].X;
					coord[(2 * j) + 1] = tfArray[j].Y;
				}
				if (point.IsCustomPropertySet("_COLLECTED_DATA_POINT"))
				{
					common.HotRegionsList.AddHotRegion(graph, path, false, point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Url), point.ReplaceKeywords(point.MapAreaAttributes), point.ReplaceKeywords(point.PostBackValue), point, ChartElementType.DataPoint);
				}
				else
				{
					common.HotRegionsList.AddHotRegion(path, false, coord, point, point.series.Name, pointIndex);
				}
			}
		}

		private double MinimumRelativePieSize(ChartArea area)
		{
			double num = 0.3;
			List<string> seriesFromChartType = area.GetSeriesFromChartType(this.Name);
			SeriesCollection series = area.Common.DataManager.Series;
			if (series[seriesFromChartType[0]].IsCustomPropertySet("MinimumRelativePieSize"))
			{
				num = ((double)CommonElements.ParseFloat(series[seriesFromChartType[0]]["MinimumRelativePieSize"])) / 100.0;
				if ((num < 0.1) || (num > 0.7))
				{
					throw new ArgumentException(SR.ExceptionPieMinimumRelativePieSizeInvalid);
				}
			}
			return num;
		}

		public void Paint(ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
		{
			foreach (Series series in common.DataManager.Series)
			{
				if ((series.IsVisible() && (series.ChartArea == area.Name)) && ((string.Compare(series.ChartTypeName, this.Name, true, CultureInfo.CurrentCulture) != 0) && !common.ChartPicture.SuppressExceptions))
				{
					throw new InvalidOperationException(SR.ExceptionChartCanNotCombine(this.Name));
				}
			}
			if (area.Area3DStyle.Enable3D)
			{
				float pieWidth = (10 * area.Area3DStyle.PointDepth) / 100;
				if (area.InnerPlotPosition.Auto)
				{
					new RectangleF(area.Position.ToRectangleF().X, area.Position.ToRectangleF().Y, area.Position.ToRectangleF().Width, area.Position.ToRectangleF().Height);
				}
				else
				{
					new RectangleF(area.PlotAreaPosition.ToRectangleF().X, area.PlotAreaPosition.ToRectangleF().Y, area.PlotAreaPosition.ToRectangleF().Width, area.PlotAreaPosition.ToRectangleF().Height);
				}
				graph.SetClip(area.Position.ToRectangleF());
				ChartArea3DStyle style1 = area.Area3DStyle;
				style1.Inclination *= -1;
				int rotation = area.Area3DStyle.Rotation;
				area.Area3DStyle.Rotation = area.GetRealYAngle();
				this.ProcessChartType3D(false, graph, common, area, pieWidth);
				ChartArea3DStyle style2 = area.Area3DStyle;
				style2.Inclination *= -1;
				area.Area3DStyle.Rotation = rotation;
				graph.ResetClip();
			}
			else
			{
				this._labelsOverlap = false;
				graph.SetClip(area.Position.ToRectangleF());
				this.SizeCorrection(graph, common, area);
				this.ProcessChartType(false, graph, common, area, false, LabelsMode.LabelsOverlap);
				if (this._labelsOverlap)
				{
					this.SizeCorrection(graph, common, area);
					this._labelsOverlap = false;
					this.ProcessChartType(false, graph, common, area, false, LabelsMode.LabelsOverlap);
				}
				this.ProcessChartType(false, graph, common, area, true, LabelsMode.Off);
				this.ProcessChartType(false, graph, common, area, false, LabelsMode.Off);
				this.ProcessChartType(false, graph, common, area, false, LabelsMode.Draw);
				graph.ResetClip();
			}
		}

		private DataPoint[] PointOrder(Series series, ChartArea area, out float[] newStartAngleList, out float[] newSweepAngleList, out int[] newPointIndexList, out bool sameBackFrontPoint)
		{
			int index = -1;
			int num5 = -1;
			sameBackFrontPoint = false;
			double num6 = 0.0;
			int num7 = 0;
			foreach (DataPoint point in series.Points)
			{
				if (point.IsEmpty)
				{
					num7++;
				}
				if (!point.IsEmpty)
				{
					num6 += Math.Abs(point.YValues[0]);
				}
			}
			int numOfPoints = series.Points.Count - num7;
			DataPoint[] points = new DataPoint[numOfPoints];
			float[] numArray = new float[numOfPoints];
			float[] numArray2 = new float[numOfPoints];
			int[] numArray3 = new int[numOfPoints];
			newStartAngleList = new float[numOfPoints];
			newSweepAngleList = new float[numOfPoints];
			newPointIndexList = new int[numOfPoints];
			if (num6 <= 0.0)
			{
				return null;
			}
			int num9 = 0;
			double rotation = area.Area3DStyle.Rotation;
			foreach (DataPoint point2 in series.Points)
			{
				if (point2.IsEmpty)
				{
					continue;
				}
				double num2 = (float)((Math.Abs(point2.YValues[0]) * 360.0) / num6);
				double num3 = rotation + num2;
				numArray[num9] = (float)rotation;
				numArray2[num9] = (float)num2;
				numArray3[num9] = num9;
				if (((rotation <= -90.0) && (num3 > -90.0)) || (((rotation <= 270.0) && (num3 > 270.0)) && (points[0] == null)))
				{
					index = num9;
					points[0] = point2;
					newStartAngleList[0] = numArray[num9];
					newSweepAngleList[0] = numArray2[num9];
					newPointIndexList[0] = numArray3[num9];
				}
				if (((rotation <= 90.0) && (num3 > 90.0)) || ((((rotation <= 450.0) && (num3 > 450.0)) && (num5 == -1)) && ((points[points.Length - 1] == null) || (points.Length == 1))))
				{
					num5 = num9;
					points[points.Length - 1] = point2;
					newStartAngleList[points.Length - 1] = numArray[num9];
					newSweepAngleList[points.Length - 1] = numArray2[num9];
					newPointIndexList[points.Length - 1] = numArray3[num9];
				}
				num9++;
				rotation += num2;
			}
			if ((num5 == -1) || (index == -1))
			{
				throw new InvalidOperationException(SR.ExceptionPieUnassignedFrontBackPoints);
			}
			if ((num5 == index) && (points.Length != 1))
			{
				points[points.Length - 1] = null;
				newStartAngleList[points.Length - 1] = 0f;
				newSweepAngleList[points.Length - 1] = 0f;
				newPointIndexList[points.Length - 1] = 0;
				sameBackFrontPoint = true;
			}
			if (num5 != index)
			{
				if (num5 < index)
				{
					num9 = 0;
					int num12 = 1;
					foreach (DataPoint point5 in series.Points)
					{
						if (point5.IsEmpty)
						{
							continue;
						}
						if ((num9 == num5) || (num9 == index))
						{
							num9++;
							continue;
						}
						if (num9 > index)
						{
							if (points[num12] != null)
							{
								throw new InvalidOperationException(SR.ExceptionPiePointOrderInvalid);
							}
							points[num12] = point5;
							newStartAngleList[num12] = numArray[num9];
							newSweepAngleList[num12] = numArray2[num9];
							newPointIndexList[num12] = numArray3[num9];
							num12++;
						}
						num9++;
					}
					num9 = 0;
					foreach (DataPoint point6 in series.Points)
					{
						if (point6.IsEmpty)
						{
							continue;
						}
						if ((num9 == num5) || (num9 == index))
						{
							num9++;
							continue;
						}
						if (num9 < num5)
						{
							if (points[num12] != null)
							{
								throw new InvalidOperationException(SR.ExceptionPiePointOrderInvalid);
							}
							points[num12] = point6;
							newStartAngleList[num12] = numArray[num9];
							newSweepAngleList[num12] = numArray2[num9];
							newPointIndexList[num12] = numArray3[num9];
							num12++;
						}
						num9++;
					}
					num12 = points.Length - 2;
					num9 = 0;
					foreach (DataPoint point7 in series.Points)
					{
						if (point7.IsEmpty)
						{
							continue;
						}
						if ((num9 == num5) || (num9 == index))
						{
							num9++;
							continue;
						}
						if ((num9 > num5) && (num9 < index))
						{
							if (points[num12] != null)
							{
								throw new InvalidOperationException(SR.ExceptionPiePointOrderInvalid);
							}
							points[num12] = point7;
							newStartAngleList[num12] = numArray[num9];
							newSweepAngleList[num12] = numArray2[num9];
							newPointIndexList[num12] = numArray3[num9];
							num12--;
						}
						num9++;
					}
				}
				else
				{
					int num13 = 1;
					num9 = 0;
					foreach (DataPoint point8 in series.Points)
					{
						if (point8.IsEmpty)
						{
							continue;
						}
						if ((num9 == num5) || (num9 == index))
						{
							num9++;
							continue;
						}
						if ((num9 > index) && (num9 < num5))
						{
							if (points[num13] != null)
							{
								throw new InvalidOperationException(SR.ExceptionPiePointOrderInvalid);
							}
							points[num13] = point8;
							newStartAngleList[num13] = numArray[num9];
							newSweepAngleList[num13] = numArray2[num9];
							newPointIndexList[num13] = numArray3[num9];
							num13++;
						}
						num9++;
					}
					num13 = points.Length - 2;
					num9 = 0;
					foreach (DataPoint point9 in series.Points)
					{
						if (point9.IsEmpty)
						{
							continue;
						}
						if ((num9 == num5) || (num9 == index))
						{
							num9++;
							continue;
						}
						if (num9 > num5)
						{
							if (points[num13] != null)
							{
								throw new InvalidOperationException(SR.ExceptionPiePointOrderInvalid);
							}
							points[num13] = point9;
							newStartAngleList[num13] = numArray[num9];
							newSweepAngleList[num13] = numArray2[num9];
							newPointIndexList[num13] = numArray3[num9];
							num13--;
						}
						num9++;
					}
					num9 = 0;
					foreach (DataPoint point10 in series.Points)
					{
						if (point10.IsEmpty)
						{
							continue;
						}
						if ((num9 == num5) || (num9 == index))
						{
							num9++;
							continue;
						}
						if (num9 < index)
						{
							if (points[num13] != null)
							{
								throw new InvalidOperationException(SR.ExceptionPiePointOrderInvalid);
							}
							points[num13] = point10;
							newStartAngleList[num13] = numArray[num9];
							newSweepAngleList[num13] = numArray2[num9];
							newPointIndexList[num13] = numArray3[num9];
							num13--;
						}
						num9++;
					}
				}
			}
			else
			{
				float num10 = numArray[index] + (numArray2[index] / 2f);
				bool flag = false;
				if (((num10 > -90f) && (num10 < 90f)) || ((num10 > 270f) && (num10 < 450f)))
				{
					flag = true;
				}
				int num11 = numOfPoints - num5;
				num9 = 0;
				foreach (DataPoint point3 in series.Points)
				{
					if (point3.IsEmpty)
					{
						continue;
					}
					if (num9 == num5)
					{
						num9++;
						continue;
					}
					if (num9 < num5)
					{
						if (points[num11] != null)
						{
							throw new InvalidOperationException(SR.ExceptionPiePointOrderInvalid);
						}
						points[num11] = point3;
						newStartAngleList[num11] = numArray[num9];
						newSweepAngleList[num11] = numArray2[num9];
						newPointIndexList[num11] = numArray3[num9];
						num11++;
					}
					num9++;
				}
				num9 = 0;
				num11 = 1;
				foreach (DataPoint point4 in series.Points)
				{
					if (point4.IsEmpty)
					{
						continue;
					}
					if (num9 == num5)
					{
						num9++;
						continue;
					}
					if (num9 > num5)
					{
						if (points[num11] != null)
						{
							throw new InvalidOperationException(SR.ExceptionPiePointOrderInvalid);
						}
						points[num11] = point4;
						newStartAngleList[num11] = numArray[num9];
						newSweepAngleList[num11] = numArray2[num9];
						newPointIndexList[num11] = numArray3[num9];
						num11++;
					}
					num9++;
				}
				if (flag)
				{
					this.SwitchPoints(numOfPoints, ref points, ref newStartAngleList, ref newSweepAngleList, ref newPointIndexList, index == num5);
				}
			}
			if (area.Area3DStyle.Inclination > 0)
			{
				this.SwitchPoints(numOfPoints, ref points, ref newStartAngleList, ref newSweepAngleList, ref newPointIndexList, index == num5);
			}
			return points;
		}

		internal static void PrepareData(Series series)
		{
			if ((string.Compare(series.ChartTypeName, "Pie", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(series.ChartTypeName, "Doughnut", StringComparison.OrdinalIgnoreCase) == 0))
			{
				double num = 0.0;
				if (series.IsCustomPropertySet("CollectedThreshold"))
				{
					double num2;
					if (!double.TryParse(series["CollectedThreshold"], NumberStyles.Any, CultureInfo.InvariantCulture, out num2))
					{
						throw new InvalidOperationException(SR.ExceptionDoughnutCollectedThresholdInvalidFormat);
					}
					num = num2;
					if (num < 0.0)
					{
						throw new InvalidOperationException(SR.ExceptionDoughnutThresholdInvalid);
					}
				}
				if (num > 0.0)
				{
					Chart chart = series.Chart;
					if (chart == null)
					{
						throw new InvalidOperationException(SR.ExceptionDoughnutNullReference);
					}
					Series item = new Series("PIE_ORIGINAL_DATA_" + series.Name, series.YValuesPerPoint);
					item.Enabled = false;
					item.IsVisibleInLegend = false;
					chart.Series.Add(item);
					foreach (DataPoint point in series.Points)
					{
						item.Points.Add(point.Clone());
					}
					if (series.IsCustomPropertySet("TempDesignData"))
					{
						item["TempDesignData"] = "true";
					}
					double num3 = 0.0;
					foreach (DataPoint point2 in series.Points)
					{
						if (!point2.IsEmpty)
						{
							num3 += Math.Abs(point2.YValues[0]);
						}
					}
					bool flag2 = true;
					if (series.IsCustomPropertySet("CollectedThresholdUsePercent"))
					{
						if (string.Compare(series["CollectedThresholdUsePercent"], "True", StringComparison.OrdinalIgnoreCase) != 0)
						{
							if (string.Compare(series["CollectedThresholdUsePercent"], "False", StringComparison.OrdinalIgnoreCase) != 0)
							{
								throw new InvalidOperationException(SR.ExceptionDoughnutCollectedThresholdUsePercentInvalid);
							}
							flag2 = false;
						}
						else
						{
							flag2 = true;
						}
					}
					if (flag2)
					{
						if (num > 100.0)
						{
							throw new InvalidOperationException(SR.ExceptionDoughnutCollectedThresholdInvalidRange);
						}
						num = (num3 * num) / 100.0;
					}
					DataPoint point3 = null;
					double num4 = 0.0;
					int num5 = 0;
					int index = 0;
					int num7 = 0;
					for (int i = 0; i < series.Points.Count; i++)
					{
						DataPoint point4 = series.Points[i];
						if (!point4.IsEmpty && (Math.Abs(point4.YValues[0]) <= num))
						{
							num5++;
							num4 += Math.Abs(point4.YValues[0]);
							if (point3 == null)
							{
								index = i;
								point3 = point4.Clone();
							}
							if (num5 == 2)
							{
								series.Points.RemoveAt(index);
								i--;
							}
							if (num5 > 1)
							{
								series.Points.RemoveAt(i);
								i--;
							}
						}
						point4["OriginalPointIndex"] = num7.ToString(CultureInfo.InvariantCulture);
						num7++;
					}
					if ((num5 > 1) && (point3 != null))
					{
						point3["_COLLECTED_DATA_POINT"] = "TRUE";
						point3.YValues[0] = num4;
						series.Points.Add(point3);
						if (series.IsCustomPropertySet("CollectedColor"))
						{
							ColorConverter converter = new ColorConverter();
							try
							{
								point3.Color = (Color)converter.ConvertFromString(null, CultureInfo.InvariantCulture, series["CollectedColor"]);
							}
							catch
							{
								throw new InvalidOperationException(SR.ExceptionDoughnutCollectedColorInvalidFormat);
							}
						}
						if (series.IsCustomPropertySet("CollectedSliceExploded"))
						{
							point3["Exploded"] = series["CollectedSliceExploded"];
						}
						if (series.IsCustomPropertySet("CollectedToolTip"))
						{
							point3.ToolTip = series["CollectedToolTip"];
						}
						if (series.IsCustomPropertySet("CollectedLegendText"))
						{
							point3.LegendText = series["CollectedLegendText"];
						}
						else
						{
							point3.LegendText = "Other";
						}
						if (series.IsCustomPropertySet("CollectedLabel"))
						{
							point3.Label = series["CollectedLabel"];
						}
					}
				}
			}
		}

		private bool PrepareLabels(RectangleF area)
		{
			float num = area.X + (area.Width / 2f);
			int num2 = 0;
			int num3 = 0;
			foreach (RectangleF ef in this._labelsRectangles)
			{
				if (ef.X < num)
				{
					num2++;
				}
				else
				{
					num3++;
				}
			}
			bool flag = true;
			if (num2 > 0)
			{
				double[] startOfIntervals = new double[num2];
				double[] endOfIntervals = new double[num2];
				int[] positinIndex = new int[num2];
				int index = 0;
				for (int i = 0; i < this._labelsRectangles.Count; i++)
				{
					RectangleF ef2 = (RectangleF)this._labelsRectangles[i];
					if (ef2.X < num)
					{
						startOfIntervals[index] = ef2.Top;
						endOfIntervals[index] = ef2.Bottom;
						positinIndex[index] = i;
						index++;
					}
				}
				this.SortIntervals(startOfIntervals, endOfIntervals, positinIndex);
				if (this.ArrangeOverlappingIntervals(startOfIntervals, endOfIntervals, (double)area.Top, (double)area.Bottom))
				{
					index = 0;
					for (int j = 0; j < this._labelsRectangles.Count; j++)
					{
						RectangleF ef3 = (RectangleF)this._labelsRectangles[j];
						if (ef3.X < num)
						{
							ef3.Y = (float)startOfIntervals[index];
							ef3.Height = ((float)endOfIntervals[index]) - ef3.Top;
							this._labelsRectangles[positinIndex[index]] = ef3;
							index++;
						}
					}
				}
				else
				{
					flag = false;
				}
			}
			bool flag2 = true;
			if (num3 > 0)
			{
				double[] numArray4 = new double[num3];
				double[] numArray5 = new double[num3];
				int[] numArray6 = new int[num3];
				int num7 = 0;
				for (int k = 0; k < this._labelsRectangles.Count; k++)
				{
					RectangleF ef4 = (RectangleF)this._labelsRectangles[k];
					if (ef4.X >= num)
					{
						numArray4[num7] = ef4.Top;
						numArray5[num7] = ef4.Bottom;
						numArray6[num7] = k;
						num7++;
					}
				}
				this.SortIntervals(numArray4, numArray5, numArray6);
				if (this.ArrangeOverlappingIntervals(numArray4, numArray5, (double)area.Top, (double)area.Bottom))
				{
					num7 = 0;
					for (int m = 0; m < this._labelsRectangles.Count; m++)
					{
						RectangleF ef5 = (RectangleF)this._labelsRectangles[m];
						if (ef5.X >= num)
						{
							ef5.Y = (float)numArray4[num7];
							ef5.Height = ((float)numArray5[num7]) - ef5.Top;
							this._labelsRectangles[numArray6[num7]] = ef5;
							num7++;
						}
					}
				}
				else
				{
					flag2 = false;
				}
			}
			if (flag && flag2)
			{
				return false;
			}
			return true;
		}

		private void ProcessChartType(bool selection, ChartGraphics graph, CommonElements common, ChartArea area, bool shadow, LabelsMode labels)
		{
			float startAngle = 0f;
			string strA = "";
			SeriesCollection series = common.DataManager.Series;
			if (labels == LabelsMode.LabelsOverlap)
			{
				this._labelsRectangles.Clear();
			}
			List<string> seriesFromChartType = area.GetSeriesFromChartType(this.Name);
			if (seriesFromChartType.Count != 0)
			{
				if ((seriesFromChartType.Count > 0) && series[seriesFromChartType[0]].IsCustomPropertySet("PieStartAngle"))
				{
					float num3;
					bool flag2 = float.TryParse(series[seriesFromChartType[0]]["PieStartAngle"], NumberStyles.Any, CultureInfo.InvariantCulture, out num3);
					if (flag2)
					{
						startAngle = num3;
					}
					if ((!flag2 || (startAngle > 360f)) || (startAngle < 0f))
					{
						throw new InvalidOperationException(SR.ExceptionCustomAttributeAngleOutOfRange("PieStartAngle"));
					}
				}
				if (!selection)
				{
					common.Chart.CallOnPrePaint(new ChartPaintEventArgs(series[seriesFromChartType[0]], graph, common, area.PlotAreaPosition));
				}
				double num4 = 0.0;
				foreach (DataPoint point in series[seriesFromChartType[0]].Points)
				{
					if (!point.IsEmpty)
					{
						num4 += Math.Abs(point.YValues[0]);
					}
				}
				if (num4 != 0.0)
				{
					float doughnutRadius = 60f;
					if (series[seriesFromChartType[0]].IsCustomPropertySet("DoughnutRadius"))
					{
						doughnutRadius = CommonElements.ParseFloat(series[seriesFromChartType[0]]["DoughnutRadius"]);
						if ((doughnutRadius < 0f) || (doughnutRadius > 99f))
						{
							throw new ArgumentException(SR.ExceptionPieRadiusInvalid);
						}
					}
					this.CheckPaleteColors(series[seriesFromChartType[0]].Points);
					int pointIndex = 0;
					int num7 = 0;
					foreach (DataPoint point2 in series[seriesFromChartType[0]].Points)
					{
						float num2;
						RectangleF ef;
						if (point2.IsEmpty)
						{
							pointIndex++;
							continue;
						}
						if (area.InnerPlotPosition.Auto)
						{
							ef = new RectangleF(area.Position.ToRectangleF().X, area.Position.ToRectangleF().Y, area.Position.ToRectangleF().Width, area.Position.ToRectangleF().Height);
						}
						else
						{
							ef = new RectangleF(area.PlotAreaPosition.ToRectangleF().X, area.PlotAreaPosition.ToRectangleF().Y, area.PlotAreaPosition.ToRectangleF().Width, area.PlotAreaPosition.ToRectangleF().Height);
						}
						if ((ef.Width < 0f) || (ef.Height < 0f))
						{
							return;
						}
						SizeF absoluteSize = graph.GetAbsoluteSize(new SizeF(ef.Width, ef.Height));
						float width = (absoluteSize.Width < absoluteSize.Height) ? absoluteSize.Width : absoluteSize.Height;
						SizeF relativeSize = graph.GetRelativeSize(new SizeF(width, width));
						PointF middlePoint = new PointF(ef.X + (ef.Width / 2f), ef.Y + (ef.Height / 2f));
						ef = new RectangleF(middlePoint.X - (relativeSize.Width / 2f), middlePoint.Y - (relativeSize.Height / 2f), relativeSize.Width, relativeSize.Height);
						if (this._sizeCorrection != 1f)
						{
							ef.X += (ef.Width * (1f - this._sizeCorrection)) / 2f;
							ef.Y += (ef.Height * (1f - this._sizeCorrection)) / 2f;
							ef.Width *= this._sizeCorrection;
							ef.Height *= this._sizeCorrection;
							if (area.InnerPlotPosition.Auto)
							{
								RectangleF ef4 = ef;
								ef4.X = ((ef4.X - area.Position.X) / area.Position.Width) * 100f;
								ef4.Y = ((ef4.Y - area.Position.Y) / area.Position.Height) * 100f;
								ef4.Width = (ef4.Width / area.Position.Width) * 100f;
								ef4.Height = (ef4.Height / area.Position.Height) * 100f;
								area.InnerPlotPosition.SetPositionNoAuto(ef4.X, ef4.Y, ef4.Width, ef4.Height);
							}
						}
						float sweepAngle = (float)((Math.Abs(point2.YValues[0]) / num4) * 360.0);
						bool exploded = false;
						if (point2.IsCustomPropertySet("Exploded"))
						{
							strA = point2["Exploded"];
							if (string.Compare(strA, "true", StringComparison.OrdinalIgnoreCase) == 0)
							{
								exploded = true;
							}
							else
							{
								exploded = false;
							}
						}
						Color empty = Color.Empty;
						ColorConverter converter = new ColorConverter();
						if (point2.IsCustomPropertySet("PieLineColor") || series[seriesFromChartType[0]].IsCustomPropertySet("PieLineColor"))
						{
							bool flag3 = false;
							try
							{
								empty = (Color)converter.ConvertFromString(point2.IsCustomPropertySet("PieLineColor") ? point2["PieLineColor"] : series[seriesFromChartType[0]]["PieLineColor"]);
								flag3 = false;
							}
							catch (ArgumentException)
							{
								flag3 = true;
							}
							catch (NotSupportedException)
							{
								flag3 = true;
							}
							if (flag3)
							{
								empty = (Color)converter.ConvertFromInvariantString(point2.IsCustomPropertySet("PieLineColor") ? point2["PieLineColor"] : series[seriesFromChartType[0]]["PieLineColor"]);
							}
						}
						if (exploded)
						{
							this._sliceExploded = true;
							num2 = ((2f * startAngle) + sweepAngle) / 2f;
							double num10 = (Math.Cos((num2 * 3.1415926535897931) / 180.0) * ef.Width) / 10.0;
							double num11 = (Math.Sin((num2 * 3.1415926535897931) / 180.0) * ef.Height) / 10.0;
							ef.Offset((float)num10, (float)num11);
						}
						if (common.ProcessModeRegions && (labels == LabelsMode.Draw))
						{
							this.Map(common, point2, startAngle, sweepAngle, ef, this.Doughnut, doughnutRadius, graph, pointIndex);
						}
						if (common.ProcessModePaint)
						{
							if (shadow)
							{
								double num12 = graph.GetRelativeSize(new SizeF((float)point2.series.ShadowOffset, (float)point2.series.ShadowOffset)).Width;
								if (num12 == 0.0)
								{
									break;
								}
								RectangleF rect = new RectangleF(ef.X, ef.Y, ef.Width, ef.Height);
								rect.Offset((float)num12, (float)num12);
								Color backColor = new Color();
								Color backSecondaryColor = new Color();
								Color borderColor = new Color();
								if (point2.Color.A != 0xff)
								{
									backColor = Color.FromArgb(point2.Color.A / 2, point2.series.ShadowColor);
								}
								else
								{
									backColor = point2.series.ShadowColor;
								}
								if (!point2.BackSecondaryColor.IsEmpty)
								{
									if (point2.BackSecondaryColor.A != 0xff)
									{
										backSecondaryColor = Color.FromArgb(point2.BackSecondaryColor.A / 2, point2.series.ShadowColor);
									}
									else
									{
										backSecondaryColor = point2.series.ShadowColor;
									}
								}
								else
								{
									backSecondaryColor = Color.Empty;
								}
								if (!point2.BorderColor.IsEmpty)
								{
									if (point2.BorderColor.A != 0xff)
									{
										borderColor = Color.FromArgb(point2.BorderColor.A / 2, point2.series.ShadowColor);
									}
									else
									{
										borderColor = point2.series.ShadowColor;
									}
								}
								else
								{
									borderColor = Color.Empty;
								}
								graph.DrawPieRel(rect, startAngle, sweepAngle, backColor, ChartHatchStyle.None, "", point2.BackImageWrapMode, point2.BackImageTransparentColor, point2.BackGradientStyle, backSecondaryColor, borderColor, point2.BorderWidth, point2.BorderDashStyle, true, this.Doughnut, doughnutRadius, PieDrawingStyle.Default);
							}
							else if (labels == LabelsMode.Off)
							{
								graph.StartHotRegion(point2);
								graph.DrawPieRel(ef, startAngle, sweepAngle, point2.Color, point2.BackHatchStyle, point2.BackImage, point2.BackImageWrapMode, point2.BackImageTransparentColor, point2.BackGradientStyle, point2.BackSecondaryColor, point2.BorderColor, point2.BorderWidth, point2.BorderDashStyle, false, this.Doughnut, doughnutRadius, ChartGraphics.GetPieDrawingStyle(point2));
								graph.EndHotRegion();
							}
							if (labels == LabelsMode.EstimateSize)
							{
								this.EstimateLabels(graph, middlePoint, ef.Size, startAngle, sweepAngle, point2, exploded, area);
								if (!this._labelsFit)
								{
									return;
								}
							}
							if (labels == LabelsMode.LabelsOverlap)
							{
								this.DrawLabels(graph, middlePoint, ef.Size, startAngle, sweepAngle, point2, doughnutRadius, exploded, area, true, num7, empty);
							}
							if (labels == LabelsMode.Draw)
							{
								this.DrawLabels(graph, middlePoint, ef.Size, startAngle, sweepAngle, point2, doughnutRadius, exploded, area, false, num7, empty);
							}
						}
						if ((common.ProcessModeRegions && (labels == LabelsMode.Draw)) && !common.ProcessModePaint)
						{
							this.DrawLabels(graph, middlePoint, ef.Size, startAngle, sweepAngle, point2, doughnutRadius, exploded, area, false, num7, empty);
						}
						point2.positionRel = new PointF(float.NaN, float.NaN);
						float num13 = 1f;
						if (exploded)
						{
							num13 = 1.2f;
						}
						num2 = startAngle + (sweepAngle / 2f);
						point2.positionRel.X = (((((float)Math.Cos((num2 * 3.1415926535897931) / 180.0)) * ef.Width) * num13) / 2f) + middlePoint.X;
						point2.positionRel.Y = (((((float)Math.Sin((num2 * 3.1415926535897931) / 180.0)) * ef.Height) * num13) / 2f) + middlePoint.Y;
						pointIndex++;
						num7++;
						startAngle += sweepAngle;
						if (startAngle >= 360f)
						{
							startAngle -= 360f;
						}
					}
					if ((labels == LabelsMode.LabelsOverlap) && this._labelsOverlap)
					{
						this._labelsOverlap = this.PrepareLabels(area.Position.ToRectangleF());
					}
					if (!selection)
					{
						common.Chart.CallOnPostPaint(new ChartPaintEventArgs(series[seriesFromChartType[0]], graph, common, area.PlotAreaPosition));
					}
				}
			}
		}

		private void ProcessChartType3D(bool selection, ChartGraphics graph, CommonElements common, ChartArea area, float pieWidth)
		{
			string strA = "";
			SeriesCollection series = common.DataManager.Series;
			List<string> seriesFromChartType = area.GetSeriesFromChartType(this.Name);
			if (seriesFromChartType.Count != 0)
			{
				float[] numArray;
				float[] numArray2;
				int[] numArray3;
				bool flag4;
				if (series[seriesFromChartType[0]].IsCustomPropertySet("PieStartAngle"))
				{
					int num2;
					bool flag2 = int.TryParse(series[seriesFromChartType[0]]["PieStartAngle"], NumberStyles.Any, CultureInfo.InvariantCulture, out num2);
					if (flag2)
					{
						if ((num2 > 180) && (num2 <= 360))
						{
							num2 = -(360 - num2);
						}
						area.Area3DStyle.Rotation = num2;
					}
					if ((!flag2 || (area.Area3DStyle.Rotation > 180)) || (area.Area3DStyle.Rotation < -180))
					{
						throw new InvalidOperationException(SR.ExceptionCustomAttributeAngleOutOfRange("PieStartAngle"));
					}
				}
				if (!selection)
				{
					common.Chart.CallOnPrePaint(new ChartPaintEventArgs(series[seriesFromChartType[0]], graph, common, area.PlotAreaPosition));
				}
				double num3 = 0.0;
				foreach (DataPoint point in series[seriesFromChartType[0]].Points)
				{
					if (!point.IsEmpty)
					{
						num3 += Math.Abs(point.YValues[0]);
					}
				}
				bool flag3 = false;
				foreach (DataPoint point2 in series[seriesFromChartType[0]].Points)
				{
					if (point2.IsCustomPropertySet("Exploded"))
					{
						strA = point2["Exploded"];
						if (string.Compare(strA, "true", StringComparison.OrdinalIgnoreCase) == 0)
						{
							flag3 = true;
						}
					}
				}
				float doughnutRadius = 60f;
				if (series[seriesFromChartType[0]].IsCustomPropertySet("DoughnutRadius"))
				{
					doughnutRadius = CommonElements.ParseFloat(series[seriesFromChartType[0]]["DoughnutRadius"]);
					if ((doughnutRadius < 0f) || (doughnutRadius > 99f))
					{
						throw new ArgumentException(SR.ExceptionPieRadiusInvalid);
					}
				}
				float labelLineSize = 100f;
				if (series[seriesFromChartType[0]].IsCustomPropertySet("3DLabelLineSize"))
				{
					labelLineSize = CommonElements.ParseFloat(series[seriesFromChartType[0]]["3DLabelLineSize"]);
					if ((labelLineSize < 30f) || (labelLineSize > 200f))
					{
						throw new ArgumentException(SR.ExceptionPie3DLabelLineSizeInvalid);
					}
				}
				labelLineSize = (labelLineSize * 0.1f) / 100f;
				this.CheckPaleteColors(series[seriesFromChartType[0]].Points);
				DataPoint[] dataPoints = this.PointOrder(series[seriesFromChartType[0]], area, out numArray, out numArray2, out numArray3, out flag4);
				if (dataPoints != null)
				{
					RectangleF pieRectangle = new RectangleF(area.Position.ToRectangleF().X + 1f, area.Position.ToRectangleF().Y + 1f, area.Position.ToRectangleF().Width - 2f, area.Position.ToRectangleF().Height - 2f);
					bool flag5 = false;
					foreach (DataPoint point3 in dataPoints)
					{
						if (this.GetLabelStyle(point3) == PieLabelStyle.Outside)
						{
							flag5 = true;
						}
					}
					if (flag5)
					{
						this.InitPieSize(graph, area, ref pieRectangle, ref pieWidth, dataPoints, numArray, numArray2, series[seriesFromChartType[0]], labelLineSize);
					}
					area.matrix3D.Initialize(pieRectangle, pieWidth, (float)area.Area3DStyle.Inclination, 0f, 0f, false);
					area.matrix3D.InitLight(area.Area3DStyle.LightStyle);
					for (int i = 0; i < 5; i++)
					{
						int index = 0;
						foreach (DataPoint point4 in dataPoints)
						{
							point4.positionRel = PointF.Empty;
							if (point4.IsEmpty)
							{
								index++;
							}
							else
							{
								RectangleF ef2;
								float sweepAngle = numArray2[index];
								float startAngle = numArray[index];
								if (area.InnerPlotPosition.Auto)
								{
									ef2 = new RectangleF(pieRectangle.X, pieRectangle.Y, pieRectangle.Width, pieRectangle.Height);
								}
								else
								{
									ef2 = new RectangleF(area.PlotAreaPosition.ToRectangleF().X, area.PlotAreaPosition.ToRectangleF().Y, area.PlotAreaPosition.ToRectangleF().Width, area.PlotAreaPosition.ToRectangleF().Height);
								}
								SizeF absoluteSize = graph.GetAbsoluteSize(new SizeF(ef2.Width, ef2.Height));
								float width = (absoluteSize.Width < absoluteSize.Height) ? absoluteSize.Width : absoluteSize.Height;
								SizeF relativeSize = graph.GetRelativeSize(new SizeF(width, width));
								PointF tf = new PointF(ef2.X + (ef2.Width / 2f), ef2.Y + (ef2.Height / 2f));
								ef2 = new RectangleF(tf.X - (relativeSize.Width / 2f), tf.Y - (relativeSize.Height / 2f), relativeSize.Width, relativeSize.Height);
								bool exploded = false;
								if (point4.IsCustomPropertySet("Exploded"))
								{
									strA = point4["Exploded"];
									if (string.Compare(strA, "true", StringComparison.OrdinalIgnoreCase) == 0)
									{
										exploded = true;
									}
									else
									{
										exploded = false;
									}
								}
								float num11 = 1f;
								if (flag3)
								{
									num11 = 0.82f;
									ef2.X += (ef2.Width * (1f - num11)) / 2f;
									ef2.Y += (ef2.Height * (1f - num11)) / 2f;
									ef2.Width *= num11;
									ef2.Height *= num11;
								}
								if (exploded)
								{
									this._sliceExploded = true;
									float num = ((2f * startAngle) + sweepAngle) / 2f;
									double num12 = (Math.Cos((num * 3.1415926535897931) / 180.0) * ef2.Width) / 10.0;
									double num13 = (Math.Sin((num * 3.1415926535897931) / 180.0) * ef2.Height) / 10.0;
									ef2.Offset((float)num12, (float)num13);
								}
								if (area.InnerPlotPosition.Auto)
								{
									RectangleF ef5 = ef2;
									ef5.X = ((ef5.X - area.Position.X) / area.Position.Width) * 100f;
									ef5.Y = ((ef5.Y - area.Position.Y) / area.Position.Height) * 100f;
									ef5.Width = (ef5.Width / area.Position.Width) * 100f;
									ef5.Height = (ef5.Height / area.Position.Height) * 100f;
									area.InnerPlotPosition.SetPositionNoAuto(ef5.X, ef5.Y, ef5.Width, ef5.Height);
								}
								graph.StartHotRegion(point4);
								this.Draw3DPie(i, graph, point4, area, ef2, startAngle, sweepAngle, doughnutRadius, pieWidth, flag4, exploded, numArray3[index]);
								graph.EndHotRegion();
								if ((i == 1) && (this.GetLabelStyle(point4) == PieLabelStyle.Outside))
								{
									this.FillPieLabelOutside(graph, area, ef2, pieWidth, point4, startAngle, sweepAngle, index, doughnutRadius, exploded);
								}
								if (((i == 2) && (this.GetLabelStyle(point4) == PieLabelStyle.Outside)) && (index == 0))
								{
									this.labelColumnLeft.Sort();
									this.labelColumnLeft.AdjustPositions();
									this.labelColumnRight.Sort();
									this.labelColumnRight.AdjustPositions();
								}
								index++;
							}
						}
					}
					if (!selection)
					{
						common.Chart.CallOnPostPaint(new ChartPaintEventArgs(series[seriesFromChartType[0]], graph, common, area.PlotAreaPosition));
					}
				}
			}
		}

		private void ReduceEmptySpace(double[] startOfIntervals, double[] endOfIntervals, double reduction)
		{
			for (int i = 0; i < (startOfIntervals.Length - 1); i++)
			{
				double num1 = endOfIntervals[i];
				double num4 = startOfIntervals[i + 1];
				double num2 = (startOfIntervals[i + 1] - endOfIntervals[i]) - ((startOfIntervals[i + 1] - endOfIntervals[i]) * reduction);
				for (int j = i + 1; j < startOfIntervals.Length; j++)
				{
					startOfIntervals[j] -= num2;
					endOfIntervals[j] -= num2;
				}
			}
		}

		private void ShiftIntervals(double[] startOfIntervals, double[] endOfIntervals, double startArea, double endArea)
		{
			double num = 0.0;
			if (startOfIntervals[0] < startArea)
			{
				num = startArea - startOfIntervals[0];
			}
			else if (endOfIntervals[endOfIntervals.Length - 1] > endArea)
			{
				num = endArea - endOfIntervals[endOfIntervals.Length - 1];
			}
			for (int i = 0; i < startOfIntervals.Length; i++)
			{
				startOfIntervals[i] += num;
				endOfIntervals[i] += num;
			}
		}

		private void ShiftOverlappingIntervals(double[] startOfIntervals, double[] endOfIntervals)
		{
			if (startOfIntervals.Length != endOfIntervals.Length)
			{
				throw new InvalidOperationException(SR.ExceptionPieIntervalsInvalid);
			}
			for (int i = 0; i < (startOfIntervals.Length - 1); i++)
			{
				if (endOfIntervals[i] > startOfIntervals[i + 1])
				{
					double num2 = endOfIntervals[i] - startOfIntervals[i + 1];
					this.SpreadInterval(startOfIntervals, endOfIntervals, i, Math.Floor((double)(num2 / 2.0)));
				}
			}
		}

		private void SizeCorrection(ChartGraphics graph, CommonElements common, ChartArea area)
		{
			float num = this._labelsOverlap ? this._sizeCorrection : 0.95f;
			this._sliceExploded = false;
			if (!area.InnerPlotPosition.Auto)
			{
				this._sizeCorrection = 0.95f;
			}
			else
			{
				while (num >= ((float)this.MinimumRelativePieSize(area)))
				{
					this._sizeCorrection = num;
					this.ProcessChartType(false, graph, common, area, false, LabelsMode.EstimateSize);
					if (this._labelsFit)
					{
						break;
					}
					num -= 0.05f;
				}
				if (this._sliceExploded && (this._sizeCorrection > 0.8f))
				{
					this._sizeCorrection = 0.8f;
				}
			}
		}

		private void SortIntervals(double[] startOfIntervals, double[] endOfIntervals, int[] positinIndex)
		{
			for (int i = 0; i < startOfIntervals.Length; i++)
			{
				for (int j = i; j < startOfIntervals.Length; j++)
				{
					double num = (startOfIntervals[i] + endOfIntervals[i]) / 2.0;
					double num2 = (startOfIntervals[j] + endOfIntervals[j]) / 2.0;
					if (num > num2)
					{
						double num3 = startOfIntervals[i];
						startOfIntervals[i] = startOfIntervals[j];
						startOfIntervals[j] = num3;
						num3 = endOfIntervals[i];
						endOfIntervals[i] = endOfIntervals[j];
						endOfIntervals[j] = num3;
						int num4 = positinIndex[i];
						positinIndex[i] = positinIndex[j];
						positinIndex[j] = num4;
					}
				}
			}
		}

		private void SpreadInterval(double[] startOfIntervals, double[] endOfIntervals, int splitIndex, double overlapShift)
		{
			endOfIntervals[splitIndex] -= overlapShift;
			startOfIntervals[splitIndex] -= overlapShift;
			endOfIntervals[splitIndex + 1] += overlapShift;
			startOfIntervals[splitIndex + 1] += overlapShift;
			if (splitIndex > 0)
			{
				for (int i = splitIndex - 1; i >= 0; i--)
				{
					if (endOfIntervals[i] <= (startOfIntervals[i + 1] - overlapShift))
					{
						break;
					}
					endOfIntervals[i] -= overlapShift;
					startOfIntervals[i] -= overlapShift;
				}
			}
			if ((splitIndex + 2) < (startOfIntervals.Length - 1))
			{
				for (int j = splitIndex + 2; j < startOfIntervals.Length; j++)
				{
					if (startOfIntervals[j] <= (endOfIntervals[j - 1] + overlapShift))
					{
						break;
					}
					endOfIntervals[j] += overlapShift;
					startOfIntervals[j] += overlapShift;
				}
			}
		}

		private void SwitchPoints(int numOfPoints, ref DataPoint[] points, ref float[] newStartAngleList, ref float[] newSweepAngleList, ref int[] newPointIndexList, bool sameBackFront)
		{
			float[] numArray = new float[numOfPoints];
			float[] numArray2 = new float[numOfPoints];
			int[] numArray3 = new int[numOfPoints];
			DataPoint[] pointArray = new DataPoint[numOfPoints];
			int num = 0;
			if (sameBackFront)
			{
				num = 1;
				pointArray[0] = points[0];
				numArray[0] = newStartAngleList[0];
				numArray2[0] = newSweepAngleList[0];
				numArray3[0] = newPointIndexList[0];
			}
			for (int i = num; i < numOfPoints; i++)
			{
				if (points[i] == null)
				{
					throw new InvalidOperationException(SR.ExceptionPieOrderOperationInvalid);
				}
				pointArray[((numOfPoints - i) - 1) + num] = points[i];
				numArray[((numOfPoints - i) - 1) + num] = newStartAngleList[i];
				numArray2[((numOfPoints - i) - 1) + num] = newSweepAngleList[i];
				numArray3[((numOfPoints - i) - 1) + num] = newPointIndexList[i];
			}
			points = pointArray;
			newStartAngleList = numArray;
			newSweepAngleList = numArray2;
			newPointIndexList = numArray3;
		}

		internal static bool UnPrepareData(Series series)
		{
			if (!series.Name.StartsWith("PIE_ORIGINAL_DATA_", StringComparison.Ordinal))
			{
				return false;
			}
			Chart chart = series.Chart;
			if (chart == null)
			{
				throw new InvalidOperationException(SR.ExceptionDoughnutNullReference);
			}
			Series series2 = chart.Series[series.Name.Substring(0x12)];
			series2.Points.Clear();
			if (!series.IsCustomPropertySet("TempDesignData"))
			{
				foreach (DataPoint point in series.Points)
				{
					series2.Points.Add(point);
				}
			}
			chart.Series.Remove(series);
			return true;
		}

		public virtual bool ApplyPaletteColorsToPoints
		{
			get
			{
				return true;
			}
		}

		public bool CircularChartArea
		{
			get
			{
				return false;
			}
		}

		public virtual bool DataPointsInLegend
		{
			get
			{
				return true;
			}
		}

		public virtual bool Doughnut
		{
			get
			{
				return false;
			}
		}

		public virtual bool ExtraYValuesConnectedToYAxis
		{
			get
			{
				return false;
			}
		}

		public virtual bool HundredPercent
		{
			get
			{
				return false;
			}
		}

		public virtual bool HundredPercentSupportNegative
		{
			get
			{
				return false;
			}
		}

		public virtual string Name
		{
			get
			{
				return "Pie";
			}
		}

		public virtual bool RequireAxes
		{
			get
			{
				return false;
			}
		}

		public bool SecondYScale
		{
			get
			{
				return false;
			}
		}

		public virtual bool SideBySideSeries
		{
			get
			{
				return false;
			}
		}

		public virtual bool Stacked
		{
			get
			{
				return false;
			}
		}

		public bool StackSign
		{
			get
			{
				return false;
			}
		}

		public virtual bool SupportLogarithmicAxes
		{
			get
			{
				return false;
			}
		}

		public virtual bool SupportStackedGroups
		{
			get
			{
				return false;
			}
		}

		public virtual bool SwitchValueAxes
		{
			get
			{
				return false;
			}
		}

		public virtual int YValuesPerPoint
		{
			get
			{
				return 1;
			}
		}

		public virtual bool ZeroCrossing
		{
			get
			{
				return false;
			}
		}

		internal class LabelColumn
		{
			private RectangleF _chartAreaPosition;
			private RectangleF _innerPlotPosition;
			private float _labelLineSize;
			private int _numOfInsertedLabels;
			private DataPoint[] _points;
			private bool _rightPosition = true;
			private float[] _yPositions;
			internal float columnHeight;
			internal int numOfItems;

			public LabelColumn(RectangleF position)
			{
				this._chartAreaPosition = position;
			}

			internal void AdjustPositions()
			{
				int num = 0;
				int num2 = 0;
				if (this._numOfInsertedLabels >= (this._points.Length / 2))
				{
					for (int i = 0; (i < this._points.Length) && (this._points[i] == null); i++)
					{
						num++;
					}
					for (int j = this._points.Length - 1; (j >= 0) && (this._points[j] == null); j--)
					{
						num2++;
					}
					bool flag = num > num2;
					int num5 = (num + num2) / 2;
					if (Math.Abs((int)(num - num2)) >= 2)
					{
						if (flag)
						{
							int num6 = 0;
							for (int k = num5; k < this._points.Length; k++)
							{
								if ((num + num6) > (this._points.Length - 1))
								{
									return;
								}
								this._points[k] = this._points[num + num6];
								this._points[num + num6] = null;
								num6++;
							}
						}
						else
						{
							int num8 = this._points.Length - 1;
							for (int m = (this._points.Length - 1) - num5; m >= 0; m--)
							{
								if ((num8 - num2) < 0)
								{
									return;
								}
								this._points[m] = this._points[num8 - num2];
								this._points[num8 - num2] = null;
								num8--;
							}
						}
					}
				}
			}

			private bool CheckFreeSpace(int position, bool upDirection)
			{
				if (upDirection)
				{
					if (position == 0)
					{
						return false;
					}
					for (int i = position - 1; i >= 0; i--)
					{
						if (this._points[i] == null)
						{
							return true;
						}
					}
				}
				else
				{
					if (position == (this.numOfItems - 1))
					{
						return false;
					}
					for (int j = position + 1; j < this.numOfItems; j++)
					{
						if (this._points[j] == null)
						{
							return true;
						}
					}
				}
				return false;
			}

			internal int GetLabelIndex(float y)
			{
				if (y < this._chartAreaPosition.Y)
				{
					y = this._chartAreaPosition.Y;
				}
				else if (y > this._chartAreaPosition.Bottom)
				{
					y = this._chartAreaPosition.Bottom - this.columnHeight;
				}
				return (int)((y - this._chartAreaPosition.Y) / this.columnHeight);
			}

			internal float GetLabelPosition(int index)
			{
				if ((index < 0) || (index > (this.numOfItems - 1)))
				{
					throw new InvalidOperationException(SR.Exception3DPieLabelsIndexInvalid);
				}
				return ((this._chartAreaPosition.Y + (this.columnHeight * index)) + (this.columnHeight / 2f));
			}

			internal PointF GetLabelPosition(DataPoint dataPoint)
			{
				float num3;
				PointF empty = PointF.Empty;
				int index = 0;
				foreach (DataPoint point in this._points)
				{
					if (point == dataPoint)
					{
						empty.Y = this.GetLabelPosition(index);
						break;
					}
					index++;
				}
				if (this._rightPosition)
				{
					empty.X = this._innerPlotPosition.Right + (this._chartAreaPosition.Width * this._labelLineSize);
				}
				else
				{
					empty.X = this._innerPlotPosition.Left - (this._chartAreaPosition.Width * this._labelLineSize);
				}
				float num2 = (float)Math.Atan((double)(((empty.Y - this._innerPlotPosition.Top) - (this._innerPlotPosition.Height / 2f)) / ((empty.X - this._innerPlotPosition.Left) - (this._innerPlotPosition.Width / 2f))));
				if (Math.Cos((double)num2) == 0.0)
				{
					num3 = 0f;
				}
				else
				{
					num3 = (float)((this._innerPlotPosition.Width * 0.4) - ((this._innerPlotPosition.Width * 0.4) / Math.Cos((double)num2)));
				}
				if (this._rightPosition)
				{
					empty.X += num3;
					return empty;
				}
				empty.X -= num3;
				return empty;
			}

			internal void Initialize(RectangleF rectangle, bool rightPosition, int maxNumOfRows, float labelLineSize)
			{
				this.numOfItems = Math.Max(this.numOfItems, maxNumOfRows);
				this.columnHeight = this._chartAreaPosition.Height / ((float)this.numOfItems);
				this._innerPlotPosition = rectangle;
				this._points = new DataPoint[this.numOfItems];
				this._yPositions = new float[this.numOfItems];
				this._rightPosition = rightPosition;
				this._labelLineSize = labelLineSize;
			}

			internal void InsertLabel(DataPoint point, float yCoordinate, int pointIndx)
			{
				int labelIndex = this.GetLabelIndex(yCoordinate);
				if (this._points[labelIndex] != null)
				{
					if ((pointIndx % 2) == 0)
					{
						if (this.CheckFreeSpace(labelIndex, false))
						{
							this.MoveLabels(labelIndex, false);
						}
						else
						{
							this.MoveLabels(labelIndex, true);
						}
					}
					else if (this.CheckFreeSpace(labelIndex, true))
					{
						this.MoveLabels(labelIndex, true);
					}
					else
					{
						this.MoveLabels(labelIndex, false);
					}
				}
				this._points[labelIndex] = point;
				this._yPositions[labelIndex] = yCoordinate;
				this._numOfInsertedLabels++;
			}

			private void MoveLabels(int position, bool upDirection)
			{
				if (upDirection)
				{
					DataPoint point = this._points[position];
					float num = this._yPositions[position];
					this._points[position] = null;
					this._yPositions[position] = 0f;
					for (int i = position; i > 0; i--)
					{
						if (this._points[i - 1] == null)
						{
							this._points[i - 1] = point;
							this._yPositions[i - 1] = num;
							return;
						}
						DataPoint point2 = this._points[i - 1];
						float num3 = this._yPositions[i - 1];
						this._points[i - 1] = point;
						this._yPositions[i - 1] = num;
						point = point2;
						num = num3;
					}
				}
				else
				{
					DataPoint point3 = this._points[position];
					float num4 = this._yPositions[position];
					this._points[position] = null;
					this._yPositions[position] = 0f;
					for (int j = position; j < (this.numOfItems - 1); j++)
					{
						if (this._points[j + 1] == null)
						{
							this._points[j + 1] = point3;
							this._yPositions[j + 1] = num4;
							return;
						}
						DataPoint point4 = this._points[j + 1];
						float num6 = this._yPositions[j + 1];
						this._points[j + 1] = point3;
						this._yPositions[j + 1] = num4;
						point3 = point4;
						num4 = num6;
					}
				}
			}

			internal void Sort()
			{
				for (int i = 0; i < this._points.Length; i++)
				{
					for (int j = 0; j < i; j++)
					{
						if (((this._yPositions[i] < this._yPositions[j]) && (this._points[i] != null)) && (this._points[j] != null))
						{
							float num3 = this._yPositions[i];
							DataPoint point = this._points[i];
							this._yPositions[i] = this._yPositions[j];
							this._points[i] = this._points[j];
							this._yPositions[j] = num3;
							this._points[j] = point;
						}
					}
				}
			}
		}

		private enum LabelsMode
		{
			Off,
			Draw,
			EstimateSize,
			LabelsOverlap
		}
	}
}

